cita 0.17 在A合约中用new的方式构造B合约后,调用B合约的成员函数,出现Couldn’t decode uint256 from ABI的错误。同样的合约在以太坊测试网上是可以运行的。
合约A:
pragma solidity ^0.4.16;
import “./Test2.sol”;
contract Test1 {
Test2 public test2;
function Test1() {
}
function setTest2(address _address) {
test2 = Test2(_address);
}
function getTest2Value() constant returns (uint256 test2value) {
return test2.getValue();
}
function getValue() returns (uint256 value) {
return 128;
}
}
合约B:
pragma solidity ^0.4.16;
contract Test2 {
function Test2() {
}
function getValue() constant returns (uint256 value) {
return 256;
}
}
合约在js中的使用方法:
let test1Ins = null;
let test2Ins = null;
let test2Address = ‘’;
this.web3.appchain.getBlockNumber()
.then((blockNumber) => {
tx.validUntilBlock = blockNumber + 88;
test1Ins = new this.web3.appchain.Contract(Test1[‘abi’]);
return test1Ins.deploy({data: Test1[‘bytecode’]})
.send(tx);
}).then(txRes => {
return this.web3.listeners.listenToTransactionReceipt(txRes.hash);
}).then( receipt => {
alert("Test1’s receipt is : " + JSON.stringify(receipt));
this.saleAuctionContractAddress = receipt.contractAddress;
console.log('auction address is ’ + receipt.contractAddress);
test1Ins.options.address = receipt.contractAddress;
return test1Ins.methods.getValue().call();
}).then(res => {
alert("Test1’s value is " + res);
return this.web3.appchain.getBlockNumber();
}).then(blockNumber => {
tx.validUntilBlock = blockNumber + 88;
test2Ins = new this.web3.appchain.Contract(Test2[‘abi’]);
return test2Ins.deploy({data: Test2[‘bytecode’]})
.send(tx);
}).then(txRes => {
return this.web3.listeners.listenToTransactionReceipt(txRes.hash);
}).then( receipt => {
alert("Test2 Receipt is : " + JSON.stringify(receipt));
this.saleAuctionContractAddress = receipt.contractAddress;
console.log('auction address is ’ + receipt.contractAddress);
test2Ins.options.address = receipt.contractAddress;
test2Address = receipt.contractAddress;
return test2Ins.methods.getValue().call();
}).then(res => {
alert("Test2’s value is " + res);
return this.web3.appchain.getBlockNumber();
}).then(blockNumber => {
tx.validUntilBlock = blockNumber + 88;
return test1Ins.methods.setTest2(test2Address).send(tx);
}).then(res => {
return this.web3.listeners.listenToTransactionReceipt(res.hash);
}).then(receipt => {
alert("SetTest2 Receipt is : " + JSON.stringify(receipt));
return test1Ins.methods.getTest2Value().call();
}).then(res => {
alert("Test2’s in test1 is " + res);
}).catch(e => {
alert("Exception: " + e);
})