Embark 2.0
To Update to 2.0.1
important
Embark's npm package has changed from embark-framework
to embark
, this sometimes can create conflicts. To update first uninstall embark-framework 1 to avoid any conflicts.
npm uninstall -g embark-framework
followed by
npm install -g embark
afterwards make sure embark version
returns 2.0.0
Embark 2.0
Embark 2.0 was developed from the ground-up, some functionality is similar, but generally projects will need to be migrated to be compatible. There is also introduction of new tools and better integrations with other platforms.
Dashboard
Embark 2 comes with a terminal dashboard.
The dashboard will tell you the state of your contracts, the enviroment you are using, and what embark is doing at the moment.
available services
Available Services will display the services available to your dapp in green, if one of these is down then it will be displayed in red.
logs and console
There is a console at the bottom which can be used to interact with contracts or with embark itself. type help
to see a list of available commands, more commands will be added with each version of Embark.
Contract & Blockchain Configuration
The configuration files have changed from the yaml format to the json format.
There is a default
environment whose configuration applies to all environments and a configuration specific to an environment will override (merge) it. So when running in development, Embark will take the configuration of both default and development to configure the contracts.
There is the option to specify the gas
directive as auto
and embark will take care of the limit automatically, this value can be changed to a specific gas value.
More information on the what it's possible to with contracts.json, including interdependent contracts, instances, etc.. can be found on the readme
# config/contracts.json
{
"default": {
"MyContract": {
"args": [
"defaultAll"
]
}
},
"development": {
"gas": "auto",
"contracts": {
"MyContract": {
"args": [
"developmentOnly"
]
}
}
}
}
EmbarkJS
EmbarkJS is a javascript library meant to abstract and facilitate the development of DApps.
promises
methods in EmbarkJS contracts will be converted to promises.
var myContract = new EmbarkJS.Contract({abi: abiObject, address: "0x123"});
myContract.get().then(function(value) { console.log("value is " + value.toNumber) });
deployment
Client side deployment will be automatically available in Embark for existing contracts:
SimpleStorage.deploy().then(function(anotherSimpleStorage) {});
or it can be manually defined as
var myContract = new EmbarkJS.Contract({abi: abiObject, code: code});
myContract.deploy().then(function(anotherMyContractObject) {});
EmbarkJS - Storage
initialization
The current available storage is IPFS. it can be initialized as
EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'})
Saving Text
EmbarkJS.Storage.saveText("hello world").then(function(hash) {});
Retrieving Data/Text
EmbarkJS.Storage.get(hash).then(function(content) {});
Uploading a file
<input type="file">
var input = $("input[type=file"]);
EmbarkJS.Storage.uploadFile(input).then(function(hash) {});
Generate URL to file
EmbarkJS.Storage.getUrl(hash);
EmbarkJS - Communication
initialization
The current available communication is Whisper.
listening to messages
EmbarkJS.Messages.listenTo({topic: ["achannel", "anotherchannel"]}).then(function(message) { console.log("received: " + message); })
sending messages
you can send plain text
EmbarkJS.Messages.sendMessage({topic: "achannel", data: 'hello world'})
or an object
EmbarkJS.Messages.sendMessage({topic: "achannel", data: {msg: 'hello world'}})
Tests
The tests changed, you can now specify your own contract config including arbitrary arguments and the same bells and whistles contracts.json
allows, including references, instances, etc..
You can run specs with embark test
, it will run any test files under test/
.
# test/simple_storage_spec.js
var assert = require('assert');
var Embark = require('embark-framework');
var EmbarkSpec = Embark.initTests();
var web3 = EmbarkSpec.web3;
describe("SimpleStorage", function() {
before(function(done) {
var contractsConfig = {
"SimpleStorage": {
args: [100]
}
};
EmbarkSpec.deployAll(contractsConfig, done);
});
it("should set constructor value", function(done) {
SimpleStorage.storedData(function(err, result) {
assert.equal(result.toNumber(), 100);
done();
});
});
it("set storage value", function(done) {
SimpleStorage.set(150, function() {
SimpleStorage.get(function(err, result) {
assert.equal(result.toNumber(), 150);
done();
});
});
});
});
Embark uses Mocha by default, but you can use any testing framework you want.
Pipeline
Embark now comes with its own pipeline by default, however plugins for grunt and meteor will soon follow for developers who prefer those workflows.
# embark.json
{
"contracts": ["app/contracts/**"],
"app": {
"css/app.css": ["app/css/**"],
"js/app.js": ["embark.js", "app/js/**"],
"index.html": "app/index.html"
},
"buildDir": "dist/",
"config": "config/"
}
Next Steps
Embark 2.1.0 will soon follow including solc 0.4.0. The following versions of Embark will focus on continuing the roadmap headlined at Devcon plus some new features to be announced.
Donations
If you like Embark please consider donating to 0x8811FdF0F988f0CD1B7E9DE252ABfA5b18c1cDb1