我用params调用方法:
{
"jsonrpc":"2.0",
"method":"eth_estimateGas",
"params": [
{
"to": "0x8f0921f30555624143d427b340b1156914882c10",
"data":"0xa9059cbb0000000000000000000000001fb330ab08bdba6e218e55fabc357643cf8252e300000000000000000000000000000000000000000000000000005af3107a4000"
}
],
"id":1
}但我总是会犯错误:
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32000,
"message": "gas required exceeds allowance or always failing transaction"
}
}0x8f0921f30555624143d427b340b1156914882c10这是一些ERC-20令牌的地址.当我把这份合同换成别人的时候,一切都很好。有什么问题吗?
发布于 2019-02-11 18:02:03
eth_estimateGas JSON调用最终导致在data字段中定义的契约函数的“试用执行”。对于ERC20传输,此函数(通常是这样)如下所示:
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}注意,在发送方的平衡中有一个对msg.sender的非本地引用和一个require()。
尝试将一个from字段添加到您的JSON params数据中;这将在msg.sender中提供一个值,并有希望使require()成功。
注:这肯定不是直观的,估计气体将需要一个平衡检查。
https://ethereum.stackexchange.com/questions/47841
复制相似问题