当我使用编译器的输出发布 new 合约时,我会得到一个javascript对象" somecontract"我可以像这样调用方法:" somecontract.doSomething();"
但是,我如何与过去某个时间点发布到区块链的合同互动?
答案 0 :(得分:7)
如果您已经拥有合同地址,请跳至下面的代码段。如果没有,你需要找到它。
要获取abi,请重新编译合同(通常在此处https://chriseth.github.io/browser-solidity/)。现在您已获得abi和合同地址,您已准备好重新获得合同。
var abi = <cut and paste the contract abi here>;
var contract = web3.eth.contract(abi).at(<contract address>);
contract.functionname();
contract.functionname.sendTransaction(...);
这是来自https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/05_greeter.sol
的样本abi[{"constant":false,"inputs":[],"name":"kill","outputs":[],"type":"function"},
{"constant":true,"inputs":[],"name":"getBlockNumber","outputs":[{"name":"","type":"uint256"}],"type":"function"},
{"constant":false,"inputs":[{"name":"_newgreeting","type":"string"}],"name":"setGreeting","outputs":[],"type":"function"},
{"constant":true,"inputs":[],"name":"greet","outputs":[{"name":"","type":"string"}],"type":"function"},{"inputs":[{"name":"_greeting","type":"string"}],"type":"constructor"}]