Basic Contract Configuration
You can specify for each contract and environment its gas costs (in wei) and arguments:
// config/contracts.js
module.exports = {
"development": {
"gas": "auto",
"contracts": {
"SimpleStorage": {
"args": [
100
],
"gas": 800000,
"gasPrice": 5
}
}
}
}
If you prefer it’s also possible to specify the contract arguments by their variable name instead of a list:
// config/contracts.js
module.exports = {
"development": {
"contracts": {
"SimpleStorage": {
"args": {
"initial_value": 100
}
}
}
}
}
Specifying Contract Dependencies
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.
You can also specify interfaces and choose to not deploy contracts (e.g. in case they are interfaces)
// config/contracts.js
module.exports = {
...
"development": {
"contracts": {
"SimpleStorage": {
"args": [
100,
"$MyStorage"
]
},
"MyStorage": {
"args": [
"initial string"
]
},
"MyMainContract": {
"args": [
"$SimpleStorage"
]
},
"MyContractInteface": {
"deploy": false
}
}
}
...
}
Multiple Instances
You can deploy many instances of the same contract. E.g.
// config/contracts.js
module.exports = {
"development": {
"contracts": {
"Currency": {
"deploy": false,
"args": [
100
]
},
"Usd": {
"instanceOf": "Currency",
"args": [
200
]
},
"MyCoin": {
"instanceOf": "Currency",
"args": [
200
]
}
}
}
}
Static Addresses
Contracts’ addresses can be defined. If an address is defined the contract wouldn’t be deployed but its defined address will be used instead.
// config/contracts.js
module.exports = {
// ...
"development": {
"contracts": {
"UserStorage": {
"address": "0x123456"
},
"UserManagement": {
"args": [
"$UserStorage"
]
}
}
}
// ...
}
onDeploy Actions
You can specify actions to do after the deployment of a contract using the “onDeploy” parameter.
| onDeploy
- should be an array of JavaScript instructions that will be evaluated and executed
// config/contracts.js
module.exports = {
"development": {
"gas": "auto",
"contracts": {
"SimpleStorage": {
"args": [
100
],
"onDeploy": ["SimpleStorage.methods.set(150).send()"]
}
}
}
}
afterDeploy Actions
You can specify actions to do after ALL contracts have been deployed by using the “afterDeploy” parameter.
| afterDeploy
- should be an array of JavaScript instructions that will be evaluated and executed
// config/contracts.js
module.exports = {
"development": {
"gas": "auto",
"contracts": {
"SimpleStorage": {
"args": [
100
]
}
},
"afterDeploy": [
"SimpleStorage.methods.set(150).send()"
]
}
}
Specify contract file
By default embark will look for the contracts inside the folder defined in the "contracts"
property in embark.json
.
However, it’s possible to specify the contract filepath:
// config/contracts.js
module.exports = {
"development": {
"gas": "auto",
"contracts": {
"SimpleStorage": {
"file": "./some_folder/simple_storage.sol",
"args": [
100
]
}
}
}
}
You can even specify files on Git, Github or over HTTP(S):
// config/contracts.js
module.exports = {
"development": {
"contracts": {
"ERC725": {
"file": "git://github.com/status/contracts/contracts/identity/ERC725.sol#develop"
},
"ERC725": {
"file": "github.com/status/contracts/contracts/identity/ERC725.sol"
},
"Ownable": {
"file": "https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/ownership/Ownable.sol"
}
}
}
}
Specify contract file from package
It’s also possible to specify a contract file from an npm package:
// config/contracts.js
module.exports = {
"development": {
"gas": "auto",
"contracts": {
"ERC20": {
"file": "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"
}
}
}
}
Conditional Deployment
You can specify a condition that decides whether a contract should be deployed by using the deployIf
field. If this field is present then the contract will deploy only if its value expression returns true.
// config/contracts.js
module.exports = {
"development": {
"contracts": {
"ERC20": {
"deployIf": "await Manager.methods.isUpdateApproved()"
},
"Manager": {
},
}
}
}
Deployment tracking
Embark’s contract deployment mechanism prevents deployment if contract code was already deployed.
It is possible to disable this feature for a given contract by setting track
configuration field to false
. This way the contract will be always deployed.
// config/contracts.js
module.exports = {
"development": {
"contracts": {
"ERC20": {
"track": false
},
"Manager": {
},
}
}
}
Solc compiler options
You can specify some options for the solidity compiler in embark.json
You can find more details here: https://solidity.readthedocs.io/en/v0.4.24/using-the-compiler.html?highlight=optimize
// embark.json
{
“options”: {
“solc”: {
“optimize”: true, // When set to true, will optimize the contracts to lower their size
“optimize-runs”: 200 // The lower the number, the higher the optimization
}
}
}