fix contract address and make module exports compatible
This commit is contained in:
parent
0eb462a89c
commit
88c1a16453
|
@ -152,6 +152,7 @@ class ABIGenerator {
|
||||||
let gasEstimates = JSON.stringify(contract.gasEstimates);
|
let gasEstimates = JSON.stringify(contract.gasEstimates);
|
||||||
|
|
||||||
contractJSON.contract_name = className;
|
contractJSON.contract_name = className;
|
||||||
|
contractJSON.address = contract.deployedAddress;
|
||||||
contractJSON.code = contract.code;
|
contractJSON.code = contract.code;
|
||||||
contractJSON.runtime_bytecode = contract.runtimeBytecode;
|
contractJSON.runtime_bytecode = contract.runtimeBytecode;
|
||||||
contractJSON.real_runtime_bytecode = contract.realRuntimeBytecode;
|
contractJSON.real_runtime_bytecode = contract.realRuntimeBytecode;
|
||||||
|
|
|
@ -97,13 +97,15 @@ class Pipeline {
|
||||||
|
|
||||||
buildContractJS(contractName) {
|
buildContractJS(contractName) {
|
||||||
let contractJSON = fs.readFileSync('dist/contracts/' + contractName + '.json').toString();
|
let contractJSON = fs.readFileSync('dist/contracts/' + contractName + '.json').toString();
|
||||||
let EmbarkJSLib = fs.readFileSync(fs.embarkPath("js/embark.js")).toString();
|
//let EmbarkJSLib = fs.readFileSync(fs.embarkPath("js/embark.js")).toString();
|
||||||
|
|
||||||
let contractCode = "";
|
let contractCode = "";
|
||||||
contractCode += contractName + "JSONConfig = " + contractJSON + ";\n";
|
contractCode += "let " + contractName + "JSONConfig = " + contractJSON + ";\n";
|
||||||
contractCode += EmbarkJSLib + "\n";
|
//contractCode += EmbarkJSLib + "\n";
|
||||||
contractCode += contractName + " = new EmbarkJS.Contract(" + contractName + "JSONConfig);\n";
|
contractCode += "let " + contractName + " = new EmbarkJS.Contract(" + contractName + "JSONConfig);\n";
|
||||||
|
contractCode += "if (typeof module !== 'undefined' && module.exports) {\n";
|
||||||
contractCode += "module.exports = " + contractName + ";\n";
|
contractCode += "module.exports = " + contractName + ";\n";
|
||||||
|
contractCode += "}\n";
|
||||||
|
|
||||||
return contractCode;
|
return contractCode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
var Web3 = require('web3');
|
||||||
|
|
||||||
|
web3 = new Web3();
|
||||||
|
|
||||||
|
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'))
|
||||||
|
|
||||||
|
EmbarkJS = require('./js/embark.js');
|
||||||
|
|
||||||
|
MyToken = require('./test_app/dist/js/mytoken.js');
|
||||||
|
|
||||||
|
console.log(MyToken.address);
|
||||||
|
|
||||||
|
MyToken.balanceOf(web3.eth.accounts[0]).then((x) => console.log(x.toNumber()));
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
"js/embark.js": ["embark.js"],
|
"js/embark.js": ["embark.js"],
|
||||||
"js/abi.js": "abi.js",
|
"js/abi.js": "abi.js",
|
||||||
"js/test.js": ["embark.js", "app/js/_vendor/jquery.min.js", "app/js/_vendor/async.min.js", "app/js/test.js"],
|
"js/test.js": ["embark.js", "app/js/_vendor/jquery.min.js", "app/js/_vendor/async.min.js", "app/js/test.js"],
|
||||||
"js/token.js": ["$Token", "app/js/token_test.js"],
|
"js/mytoken.js": ["$MyToken", "app/js/token_test.js"],
|
||||||
"index.html": "app/index.html",
|
"index.html": "app/index.html",
|
||||||
"test.html": "app/test.html",
|
"test.html": "app/test.html",
|
||||||
"test2.html": "app/test2.html"
|
"test2.html": "app/test2.html"
|
||||||
|
|
Loading…
Reference in New Issue