embark-area-51/README.md

343 lines
8.3 KiB
Markdown
Raw Normal View History

2016-09-23 05:03:20 +00:00
note: This readme refers to version 1.2.0 of Embark. Not version 2.0 which will be released soon(ish).
2015-05-25 12:21:53 +00:00
What is embark
======
2015-05-26 14:35:07 +00:00
[![Join the chat at https://gitter.im/iurimatias/embark-framework](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/iurimatias/embark-framework?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
2015-06-22 02:14:22 +00:00
2016-10-16 19:14:48 +00:00
Embark is a framework that allows you to easily develop and deploy DApps.
2015-06-22 02:14:22 +00:00
With Embark you can:
* Automatically deploy contracts and make them available in your JS code. Embark watches for changes, and if you update a contract, Embark will automatically redeploy the contracts (if needed) and the dapp.
2016-10-16 19:14:48 +00:00
* Use any build pipeline or tool you wish, including grunt and meteor. (for 1.x, plugins coming soon for 2.x series)
2015-06-22 02:14:22 +00:00
* Do Test Driven Development with Contracts using Javascript.
* Easily deploy to & use decentralized systems such as IPFS.
2015-08-31 12:33:15 +00:00
* Keep track of deployed contracts, deploy only when truly needed.
2015-10-12 22:33:00 +00:00
* Manage different chains (e.g testnet, private net, livenet)
2016-10-16 19:14:48 +00:00
* Quickly create advanced DApps using multiple contracts that can interact with decentralized infrastructure for storage and comunication.
2015-06-22 10:07:46 +00:00
2015-05-25 12:21:53 +00:00
Installation
======
2016-06-01 02:13:36 +00:00
Requirements: geth (1.4.4 or higher), node (5.0.0) and npm
2016-10-16 19:14:48 +00:00
Optional: serpent (develop) if using contracts with Serpent, testrpc or ethersim if using the simulator or the test functionality
2015-05-25 12:21:53 +00:00
```Bash
2016-10-16 19:14:48 +00:00
$ npm -g install embark
2016-09-23 22:56:19 +00:00
# If you plan to use the simulator instead of a real ethereum node.
2016-10-16 19:14:48 +00:00
$ npm -g install testrpc
2015-05-25 12:21:53 +00:00
```
2015-06-22 10:07:46 +00:00
See [Complete Installation Instructions](https://github.com/iurimatias/embark-framework/wiki/Installation).
2015-05-25 12:21:53 +00:00
Usage - Demo
======
You can easily create a sample working DApp with the following:
```Bash
$ embark demo
$ cd embark_demo
```
2015-10-12 22:33:00 +00:00
To run a ethereum rpc simulator simply run:
```Bash
$ embark simulator
```
Or Alternatively, you can run a REAL ethereum node for development purposes:
2015-05-25 12:21:53 +00:00
```Bash
$ embark blockchain
```
2015-10-12 22:33:00 +00:00
2015-05-25 12:21:53 +00:00
By default embark blockchain will mine a minimum amount of ether and will only mine when new transactions come in. This is quite usefull to keep a low CPU. The option can be configured at config/blockchain.yml
Then, in another command line:
```Bash
$ embark run
```
This will automatically deploy the contracts, update their JS bindings and deploy your DApp to a local server at http://localhost:8000
Note that if you update your code it will automatically be re-deployed, contracts included. There is no need to restart embark, refreshing the page on the browser will do.
Creating a new DApp
======
```Bash
$ embark new AppName
$ cd AppName
```
DApp Structure
======
```Bash
app/
2015-08-31 12:33:15 +00:00
|___ contracts/ #solidity or serpent contracts
2015-06-22 02:14:22 +00:00
|___ html/
|___ css/
|___ js/
2015-05-25 12:21:53 +00:00
config/
2016-10-16 19:25:40 +00:00
|___ blockchain.json #environments configuration
|___ contracts.json #contracts configuration
test/
|___ #contracts tests
2015-06-22 02:14:22 +00:00
```
2015-05-25 12:21:53 +00:00
2015-08-31 12:33:15 +00:00
Solidity/Serpent files in the contracts directory will automatically be deployed with embark run. Changes in any files will automatically be reflected in app, changes to contracts will result in a redeployment and update of their JS Bindings
2015-05-25 12:21:53 +00:00
Using Contracts
======
Embark will automatically take care of deployment for you and set all needed JS bindings. For example, the contract below:
```Javascript
# app/contracts/simple_storage.sol
contract SimpleStorage {
2015-06-22 11:54:22 +00:00
uint public storedData;
function SimpleStorage(uint initialValue) {
storedData = initialValue;
}
2015-05-25 12:21:53 +00:00
function set(uint x) {
storedData = x;
}
function get() constant returns (uint retVal) {
return storedData;
}
}
```
Will automatically be available in Javascript as:
```Javascript
# app/js/index.js
SimpleStorage.set(100);
SimpleStorage.get();
2015-06-22 11:54:22 +00:00
SimpleStorage.storedData();
2015-05-25 12:21:53 +00:00
```
2015-06-22 02:14:22 +00:00
You can specify for each contract and environment its gas costs and arguments:
2016-10-16 19:25:40 +00:00
```Json
# config/contracts.json
{
"development": {
"gas": "auto",
"contracts": {
"SimpleStorage": {
"args": [
100
]
}
}
}
}
2015-06-22 02:14:22 +00:00
```
If you are using multiple contracts, you can pass a reference to another contract as ```$ContractName```, Embark will automatically replace this with the correct address for the contract.
```Yaml
2016-10-16 20:16:09 +00:00
# config/contracts.json
{
2015-06-22 02:14:22 +00:00
...
2016-10-16 20:16:09 +00:00
"development": {
"contracts": {
"SimpleStorage": {
"args": [
100,
$MyStorage
]
},
"MyStorage": {
"args": [
"initial string"
]
},
"MyMainContract": {
"args": [
$SimpleStorage
]
}
}
}
...
}
2015-06-22 02:14:22 +00:00
```
2015-07-15 12:06:40 +00:00
You can now deploy many instances of the same contract. e.g
```Yaml
# config/contracts.yml
development:
Currency:
2015-09-01 01:02:21 +00:00
deploy: false
2015-07-15 12:06:40 +00:00
args:
- 100
Usd:
instanceOf: Currency
args:
- "initial string"
MyCoin:
instanceOf: Currency
args:
- $SimpleStorage
...
```
Contracts addresses can be defined, If an address is defined the contract wouldn't be deployed but its defined address will be used instead.
```Yaml
development:
UserStorage:
address: 0x123456
UserManagement:
args:
- $UserStorage
...
```
2015-08-31 12:33:15 +00:00
You can also define contract interfaces (Stubs) and actions to do on deployment
```Yaml
development:
DataSource:
args:
MyDataSource:
args:
instanceOf: DataSource
Manager:
stubs:
- DataSource
args:
- $MyDataSource
onDeploy:
- Manager.updateStorage($MyDataSource)
- MyDataSource.set(5)
...
```
2016-10-16 19:50:38 +00:00
EmbarkJS
======
EmbarkJS - Storage
======
EmbarkJS - Communication
======
2015-06-22 02:14:22 +00:00
Tests
======
2016-10-16 19:25:40 +00:00
You can run specs with ```embark test```, it will run any test files under ```test/```.
2015-06-22 02:14:22 +00:00
Embark includes a testing lib to fastly run & test your contracts in a EVM.
2015-06-22 02:14:22 +00:00
```Javascript
2015-10-12 22:33:00 +00:00
# test/simple_storage_spec.js
2016-10-16 19:25:40 +00:00
2015-10-12 22:33:00 +00:00
var assert = require('assert');
var Embark = require('embark-framework');
var EmbarkSpec = Embark.initTests();
2016-10-16 19:25:40 +00:00
var web3 = EmbarkSpec.web3;
2015-10-12 22:33:00 +00:00
2016-10-16 19:25:40 +00:00
describe("SimpleStorage", function() {
2015-10-12 22:33:00 +00:00
before(function(done) {
2016-10-16 19:25:40 +00:00
var contractsConfig = {
"SimpleStorage": {
args: [100]
}
};
EmbarkSpec.deployAll(contractsConfig, done);
2015-06-22 02:14:22 +00:00
});
2015-10-12 22:33:00 +00:00
it("should set constructor value", function(done) {
SimpleStorage.storedData(function(err, result) {
assert.equal(result.toNumber(), 100);
done();
});
2015-06-22 02:14:22 +00:00
});
2015-10-12 22:33:00 +00:00
it("set storage value", function(done) {
SimpleStorage.set(150, function() {
SimpleStorage.get(function(err, result) {
assert.equal(result.toNumber(), 150);
done();
});
});
2015-06-22 02:14:22 +00:00
});
2016-10-16 19:25:40 +00:00
});
2015-06-22 02:14:22 +00:00
```
2015-10-12 22:33:00 +00:00
Embark uses [Mocha](http://mochajs.org/) by default, but you can use any testing framework you want.
2015-06-22 02:14:22 +00:00
2015-05-25 12:21:53 +00:00
Working with different chains
======
2015-06-22 10:13:04 +00:00
You can specify which environment to deploy to:
2015-05-25 12:21:53 +00:00
2015-06-22 10:13:04 +00:00
```$ embark blockchain staging```
```$ embark run staging```
The environment is a specific blockchain configuration that can be managed at config/blockchain.yml
2015-05-25 12:21:53 +00:00
```Yaml
# config/blockchain.yml
...
staging:
rpc_host: localhost
rpc_port: 8101
rpc_whitelist: "*"
datadir: default
chains: chains_staging.json
2015-05-25 12:21:53 +00:00
network_id: 0
console: true
geth_extra_opts: --vmdebug
2015-05-25 12:21:53 +00:00
account:
init: false
address: 0x123
```
2015-06-22 10:18:11 +00:00
See [Configuration](https://github.com/iurimatias/embark-framework/wiki/Configuration).
2015-05-25 12:21:53 +00:00
Deploying only contracts
======
Although embark run will automatically deploy contracts, you can choose to only deploy the contracts to a specific environment
```Bash
$ embark deploy privatenet
```
embark deploy will deploy all contracts at app/contracts and return the resulting addresses
Structuring Application
======
Embark is quite flexible and you can configure you're own directory structure using ```embark.yml```
```Yaml
# embark.yml
type: "manual" #other options: meteor, grunt
contracts: ["app/contracts/**/*.sol", "app/contracts/**/*.se"] # contracts files
output: "src/embark.js" # resulting javascript interface
blockchainConfig: "config/blockchain.yml" # blockchain config
contractsConfig: "config/contracts.yml" # contracts config
```
2015-09-01 02:06:30 +00:00
Deploying to IPFS
======
To deploy a dapp to IPFS, all you need to do is run a local IPFS node and then run ```embark ipfs```.
2016-10-16 19:14:48 +00:00
If you want to deploy to the livenet then after configuring you account on ```config/blockchain.json``` on the ```production``` environment then you can deploy to that chain by specifying the environment ```embark ipfs production```.
2015-09-01 02:06:30 +00:00
2015-05-25 12:21:53 +00:00
LiveReload Plugin
======
Embark works quite well with the LiveReload Plugin