如何执行两个合同一个有另一个地址
How to exec the two contracts one has the another address
我用这个脚本部署了合同 first
和 second
。
我想在 truffle console
上测试这个合约。
然而错误来了。
first.sol
pragma solidity ^0.4.25;
contract First{
int public mydata;
function GetDouble(int _data) public returns(int _output){
mydata= _data * 2;
return _data * 2;
}
}
second.sol
pragma solidity ^0.4.25;
import "./first.sol";
contract Second{
address firstAddress;
int public _data;
constructor(address _first) public{
firstAddress = _first;
}
function SetData() public{
First h = First(firstAddress);
_data = h.GetDouble(21);
}
}
3_Custom.js
var hw = artifacts.require("First");
var hw1 = artifacts.require("Second");
module.exports = function(deployer){
deployer.deploy(hw).then
(function(){
return deployer.deploy(hw1,hw.address);
})
};
现在我想在 truffle console
上试用这个脚本。
truffle(development)> Second.address
'0xf3b9059123028a9e77f8dd3fe53b64f2e5680b80'
truffle(development)> var s = Second.at(Second.address)
truffle(development)> s.SetData(2)
Error: Invalid number of arguments to Solidity function
at new Promise (<anonymous>)
at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-contract/contract.js:204:1
at SolidityFunction.execute (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:256:1)
at SolidityFunction.sendTransaction (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:163:1)
at SolidityFunction.toPayload (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:90:1)
at SolidityFunction.validateArgs (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:74:1)
at Object.InvalidNumberOfSolidityArgs (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:25:1)
我用s.setData()
,它returns
{ tx:
'0x279aa09f95a4f96520d7d2dab2a0a3c923b7e17c393496be08ba52e89a376970',
receipt:
{ transactionHash:
'0x279aa09f95a4f96520d7d2dab2a0a3c923b7e17c393496be08ba52e89a376970',
transactionIndex: 0,
blockHash:
'0x5d0cb4929292dba726af031736d39b8521669f2c8f470186da960ba30f61063a',
blockNumber: 7,
from: '0xf20bd17dccd1e442141f7b9d93f1c8f366fc7f94',
to: '0x771939ec841204dd071fe5f3d35267461c4c2109',
gasUsed: 25645,
cumulativeGasUsed: 25645,
contractAddress: null,
logs: [],
status: '0x1',
logsBloom:
'0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' },
logs: [] }
truffle(development)> s.SetData(2)
Error: Invalid number of arguments to Solidity function
您试图将参数传递给 SetData
函数,但它的定义(在 Second
合同中)包含 0 个参数:
function SetData() public{
我用这个脚本部署了合同 first
和 second
。
我想在 truffle console
上测试这个合约。
然而错误来了。
first.sol
pragma solidity ^0.4.25;
contract First{
int public mydata;
function GetDouble(int _data) public returns(int _output){
mydata= _data * 2;
return _data * 2;
}
}
second.sol
pragma solidity ^0.4.25;
import "./first.sol";
contract Second{
address firstAddress;
int public _data;
constructor(address _first) public{
firstAddress = _first;
}
function SetData() public{
First h = First(firstAddress);
_data = h.GetDouble(21);
}
}
3_Custom.js
var hw = artifacts.require("First");
var hw1 = artifacts.require("Second");
module.exports = function(deployer){
deployer.deploy(hw).then
(function(){
return deployer.deploy(hw1,hw.address);
})
};
现在我想在 truffle console
上试用这个脚本。
truffle(development)> Second.address
'0xf3b9059123028a9e77f8dd3fe53b64f2e5680b80'
truffle(development)> var s = Second.at(Second.address)
truffle(development)> s.SetData(2)
Error: Invalid number of arguments to Solidity function
at new Promise (<anonymous>)
at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-contract/contract.js:204:1
at SolidityFunction.execute (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:256:1)
at SolidityFunction.sendTransaction (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:163:1)
at SolidityFunction.toPayload (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:90:1)
at SolidityFunction.validateArgs (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/function.js:74:1)
at Object.InvalidNumberOfSolidityArgs (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:25:1)
我用s.setData()
,它returns
{ tx:
'0x279aa09f95a4f96520d7d2dab2a0a3c923b7e17c393496be08ba52e89a376970',
receipt:
{ transactionHash:
'0x279aa09f95a4f96520d7d2dab2a0a3c923b7e17c393496be08ba52e89a376970',
transactionIndex: 0,
blockHash:
'0x5d0cb4929292dba726af031736d39b8521669f2c8f470186da960ba30f61063a',
blockNumber: 7,
from: '0xf20bd17dccd1e442141f7b9d93f1c8f366fc7f94',
to: '0x771939ec841204dd071fe5f3d35267461c4c2109',
gasUsed: 25645,
cumulativeGasUsed: 25645,
contractAddress: null,
logs: [],
status: '0x1',
logsBloom:
'0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' },
logs: [] }
truffle(development)> s.SetData(2)
Error: Invalid number of arguments to Solidity function
您试图将参数传递给 SetData
函数,但它的定义(在 Second
合同中)包含 0 个参数:
function SetData() public{