我正在尝试测试简单的传输方法(将某人的以太转移到另一个),但是 remix(solidity web 编译器)说
transact to browser/Exchange.sol:Exchange.transfer pending ...
transact to browser/Exchange.sol:Exchange.transfer errored: Error: VM Exception while executing eth_estimateGas: invalid opcode
at /Users/strender/.nvm/versions/node/v8.8.1/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:59368:17
at /Users/strender/.nvm/versions/node/v8.8.1/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:69306:5
at /Users/strender/.nvm/versions/node/v8.8.1/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:11335:9
at /Users/strender/.nvm/versions/node/v8.8.1/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:7895:16
at replenish (/Users/strender/.nvm/versions/node/v8.8.1/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:8415:25)
at iterateeCallback (/Users/strender/.nvm/versions/node/v8.8.1/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:8405:17)
at /Users/strender/.nvm/versions/node/v8.8.1/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:8380:16
at /Users/strender/.nvm/versions/node/v8.8.1/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:11332:13
at /Users/strender/.nvm/versions/node/v8.8.1/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:69302:9
at /Users/strender/.nvm/versions/node/v8.8.1/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:63982:7
而且,我的 Solidity 文件结构是
pragma solidity ^0.4.18;
contract Exchange {
mapping (address => uint256) public balances;
string public helloworld;
event LogDeposit(address sender, uint amount);
event LogWithdraw(address receiver, uint amount);
event LogTransfer(address sender, address receiver, uint amount);
event HelloworldEvent(string helloworld);
function Exchange() {
helloworld = "helloworld!";
}
function helloWorld() returns (string) {
return helloworld;
}
function deposit() payable returns(bool success) {
balances[msg.sender] += msg.value;
LogDeposit(msg.sender, msg.value);
return true;
}
function withdraw(uint value) returns (bool success) {
if (balances[msg.sender] < value) throw;
balances[msg.sender] -= value;
msg.sender.transfer(value);
LogWithdraw(msg.sender, value);
return true;
}
function transfer(address to, uint value) payable returns (bool success) {
if (balances[msg.sender] < value) throw;
balances[msg.sender] -= value;
to.transfer(value);
LogTransfer(msg.sender, to, value);
return true;
}
}
并且,在 web3 javascript 上,我尝试像这样调用函数“transfer(address to, uint value):
$("#button").click(function() {
Exchange.transfer(receiver.toString(), 2);
// $("#loader").show();
});
当我向此 Exchange.transfer() 方法添加一些 gas、value 参数时,VM 返回“基本费用超过 gas 限制”