Skip to content

Commit 88c1a16

Browse files
committed
fix contract address and make module exports compatible
1 parent 0eb462a commit 88c1a16

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

lib/contracts/abi.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class ABIGenerator {
152152
let gasEstimates = JSON.stringify(contract.gasEstimates);
153153

154154
contractJSON.contract_name = className;
155+
contractJSON.address = contract.deployedAddress;
155156
contractJSON.code = contract.code;
156157
contractJSON.runtime_bytecode = contract.runtimeBytecode;
157158
contractJSON.real_runtime_bytecode = contract.realRuntimeBytecode;

lib/pipeline/pipeline.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,15 @@ class Pipeline {
9797

9898
buildContractJS(contractName) {
9999
let contractJSON = fs.readFileSync('dist/contracts/' + contractName + '.json').toString();
100-
let EmbarkJSLib = fs.readFileSync(fs.embarkPath("js/embark.js")).toString();
100+
//let EmbarkJSLib = fs.readFileSync(fs.embarkPath("js/embark.js")).toString();
101101

102102
let contractCode = "";
103-
contractCode += contractName + "JSONConfig = " + contractJSON + ";\n";
104-
contractCode += EmbarkJSLib + "\n";
105-
contractCode += contractName + " = new EmbarkJS.Contract(" + contractName + "JSONConfig);\n";
103+
contractCode += "let " + contractName + "JSONConfig = " + contractJSON + ";\n";
104+
//contractCode += EmbarkJSLib + "\n";
105+
contractCode += "let " + contractName + " = new EmbarkJS.Contract(" + contractName + "JSONConfig);\n";
106+
contractCode += "if (typeof module !== 'undefined' && module.exports) {\n";
106107
contractCode += "module.exports = " + contractName + ";\n";
108+
contractCode += "}\n";
107109

108110
return contractCode;
109111
}

script_test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var Web3 = require('web3');
2+
3+
web3 = new Web3();
4+
5+
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'))
6+
7+
EmbarkJS = require('./js/embark.js');
8+
9+
MyToken = require('./test_app/dist/js/mytoken.js');
10+
11+
console.log(MyToken.address);
12+
13+
MyToken.balanceOf(web3.eth.accounts[0]).then((x) => console.log(x.toNumber()));
14+

test_app/embark.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"js/embark.js": ["embark.js"],
88
"js/abi.js": "abi.js",
99
"js/test.js": ["embark.js", "app/js/_vendor/jquery.min.js", "app/js/_vendor/async.min.js", "app/js/test.js"],
10-
"js/token.js": ["$Token", "app/js/token_test.js"],
10+
"js/mytoken.js": ["$MyToken", "app/js/token_test.js"],
1111
"index.html": "app/index.html",
1212
"test.html": "app/test.html",
1313
"test2.html": "app/test2.html"

0 commit comments

Comments
 (0)