fix(@embark/site): update contractGeneration plugin api

This commit is contained in:
Jonathan Rainville 2019-07-04 16:36:09 -04:00 committed by Michael Bradley
parent c87d7da4cc
commit ad796bc8f8
1 changed files with 22 additions and 17 deletions

View File

@ -164,31 +164,36 @@ example:
## .registerContractsGeneration(callback(options))
By default Embark will use EmbarkJS to declare contracts in the dapp. You can override and use your own client side library.
By default Embark will use EmbarkJS to declare contracts in the Dapp. You can override that and use your own client side library.
Available options:
* contracts - Hash of objects containing all the deployed contracts. (key: contractName, value: contract object)
* abiDefinition
* code
* deployedAddress
* gasEstimates
* gas
* gasPrice
* runtimeByteCode
* abiDefinition
* code
* deployedAddress
* gasEstimates
* gas
* gasPrice
* runtimeByteCode
Returns `string`
```
embark.registerContractsGeneration(function (options) {
const contractGenerations = [];
Object.keys(options.contracts).map(className => {
const contract = options.contracts[className];
const abi = JSON.stringify(contract.abiDefinition);
The generated string will be used to create the contract objects in the Embark console and will be generated in `embarkArtifacts` so that the Dapp can use them.
contractGenerations.push(`${className} = web3.eth.contract('${abi}').at('${contract.deployedAddress}')`);
```
module.exports = (embark) => {
embark.registerContractsGeneration((options) => {
const contractGenerations = [];
Object.keys(options.contracts).map(className => {
const contract = options.contracts[className];
const abi = JSON.stringify(contract.abiDefinition);
contractGenerations.push(`${className} = new web3.eth.Contract(${abi}, '${contract.deployedAddress}');
module.exports = ${className};`);
});
return contractGenerations.join('\n');
});
return contractGenerations.join('\n');
});
};
```
## .registerConsoleCommand(options)