我已经用同样的错误阅读了其他的主题,但这并没有解决我的问题.
当我试图与我的智能契约在web接口之间进行测试rpc通信时,我总是出错“处理事务时的vm异常: out of gas",而当我的智能契约中只有4个输入时,就没有问题了。
我已经尝试使用它来启动tesrpc (因为只有没有工作的testrpc ):
--account="0x7231a774a538fce22a329729b03087de4cb4a1119494db1c10eae3bb491823e7,10000000000000000000“
介电常数-l 4500000000000
测试--汽油价格20000
介电常数-g 1000000000000000
不管我用的是什么,气体使用量保持在90000,我认为错误与此有关……感谢帮助我的人!
这是我的合同:
pragma solidity ^0.4.18;
contract URP {
uint8 x1;
uint8 x2;
uint8 y1;
uint8 y2;
uint8 z1;
uint8 z2;
uint8 retailer;
uint8 value;
uint8 x;
uint8 y;
uint8 z;
uint8 shopper;
function SendCoin(uint8 _x1, uint8 _x2, uint8 _y1, uint8 _y2, uint8 _z1, uint8 _z2, uint8 _ret, uint8 _value, uint8 _x, uint8 _y, uint8 _z, uint8 _shop) public {
x1 = _x1;
x2 = _x2;
y1 = _y1;
y2 = _y2;
z1 = _z1;
z2 = _z2;
retailer = _retailer;
value = _value;
x = _x;
y = _y;
z =_z;
shopper = _shopper;
}
function getSendCoin() public constant returns (uint8, uint8, uint8, uint8, uint8, uint8, uint8, uint8, uint8, uint8, uint8, uint8) {
return (x1, x2, y1, y2, z1, z2, retailer, value, x, y, z, shopper);
}
}这是我的网页界面:
Document
SendCoin
x1
x2
y1
y2
z1
z2
retailer
value
x
y
z
shopper
Push Data
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
// set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
web3.eth.defaultAccount = web3.eth.accounts[0];
var URPContract = web3.eth.contract([
{
"constant": true,
"inputs": [],
"name": "getSendCoin",
"outputs": [
{
"name": "",
"type": "uint8"
},
{
"name": "",
"type": "uint8"
},
{
"name": "",
"type": "uint8"
},
{
"name": "",
"type": "uint8"
},
{
"name": "",
"type": "uint8"
},
{
"name": "",
"type": "uint8"
},
{
"name": "",
"type": "uint8"
},
{
"name": "",
"type": "uint8"
},
{
"name": "",
"type": "uint8"
},
{
"name": "",
"type": "uint8"
},
{
"name": "",
"type": "uint8"
},
{
"name": "",
"type": "uint8"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_x1",
"type": "uint8"
},
{
"name": "_x2",
"type": "uint8"
},
{
"name": "_y1",
"type": "uint8"
},
{
"name": "_y2",
"type": "uint8"
},
{
"name": "_z1",
"type": "uint8"
},
{
"name": "_z2",
"type": "uint8"
},
{
"name": "_retailer",
"type": "uint8"
},
{
"name": "_value",
"type": "uint8"
},
{
"name": "_x",
"type": "uint8"
},
{
"name": "_y",
"type": "uint8"
},
{
"name": "_z",
"type": "uint8"
},
{
"name": "_shopper",
"type": "uint8"
}
],
"name": "SendCoin",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}]);
web3.eth.accounts.forEach (account => {
balance = web3.eth.getBalance (account);
console.log (balance);
})
var URP = URPContract.at('0x538882ec49974f8815fee55ad7b40d6dd4b6b75d');
console.log(URP);
URP.getSendCoin(function(error, result){
if(!error)
{
$("#sendcoin").html(result[0]+' = x1 / x2 = '+result[1]+' / y1 = '+result[2]+' / y2 = '+result[3]+' / z1 = ' +result[4]+' / z2 = ' +result[5]+' / ret = '+result[6]+' / value = ' +result[7]+' / x = '+result[8]+' / y = '+result[9]+' / z = '+result[10]+' / shop = '+result[11] );
console.log(result);
}
else
console.error(error);
});
$("#button").click(function() {
URP.SendCoin($("#x1").val(), $("#x2").val(), $("#y1").val(), $("#y2").val(), $("#z1").val(), $("#z2").val(), $("#retailer").val(), $("#value").val(), $("#x").val(), $("#y").val(), $("#z").val(), $("#shopper").val());
});抱歉我的ABI太长了..。
发布于 2018-05-07 13:22:19
SendCoin方法将消耗102912个单元。我建议您使用estimateGas()函数。它将返回给定输入的气体消耗量。
请参阅以下修改的代码:
$("#button").click(function() {
var _gas = URP.SendCoin.estimateGas($("#x1").val(), $("#x2").val(), $("#y1").val(), $("#y2").val(), $("#z1").val(), $("#z2").val(), $("#retailer").val(), $("#value").val(), $("#x").val(), $("#y").val(), $("#z").val(), $("#shopper").val());
_gas = Math.floor(gas*1.2); //For safe side.
URP.SendCoin($("#x1").val(), $("#x2").val(), $("#y1").val(), $("#y2").val(), $("#z1").val(), $("#z2").val(), $("#retailer").val(), $("#value").val(), $("#x").val(), $("#y").val(), $("#z").val(), $("#shopper").val(), {from:'your account', gas:_gas});
});我建议您使用异步方法的. MetaMask不会执行同步方法。
发布于 2018-05-07 16:56:39
试试testrpc --gas-limit 4600000。
请记住,testrpc已改为ganache-cli。我运行ganache-cli --gas-limit 4600000
另外,确保配置了您的truffle.js。你可以改变汽油价格和汽油价格。
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "0",
gas: 10000000,
gasLimit: 10000000
},
}https://ethereum.stackexchange.com/questions/47792
复制相似问题