Ich habe bereits die anderen Themen mit dem gleichen Fehler gelesen, aber das hat mein Problem nicht gelöst ...
Wenn ich versuche, mit Test-RPC zwischen meiner Webschnittstelle und meinem Smart-Vertrag zu kommunizieren, erhalte ich immer den Fehler „VM-Ausnahme während der Verarbeitung der Transaktion: kein Gas mehr“, während es kein Problem gibt, wenn ich nur 4 Eingaben in meinem Smart-Vertrag habe.
Ich habe bereits versucht, damit tesrpc zu initiieren (weil nur testrpc nicht funktioniert hat):
testrpc --account="0x7231a774a538fce22a329729b03087de4cb4a1119494db1c10eae3bb491823e7, 1000000000000000000000"
testrpc -l 450000000000
testrpc --gasPrice 20000
testrpc -g 1000000000000000
Egal was ich verwende, der Gasverbrauch bleibt bei 90000 und ich denke, der Fehler hängt damit zusammen ... Danke an die Person, die mir helfen wird!
Hier mein Vertrag:
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);
}
}
Und hier ist mein Webinterface:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="main.css">
<script src="./node_modules/web3/dist/web3.min.js"></script>
</head>
<body>
<div class="container">
<h1>SendCoin</h1>
<h2 id="sendcoin"></h2>
<label for="name" class="col-lg-2 control-label">x1</label>
<input id="x1" type="text">
<label for="name" class="col-lg-2 control-label">x2</label>
<input id="x2" type="text">
<label for="name" class="col-lg-2 control-label">y1</label>
<input id="y1" type="text">
<label for="name" class="col-lg-2 control-label">y2</label>
<input id="y2" type="text">
<label for="name" class="col-lg-2 control-label">z1</label>
<input id="z1" type="text">
<label for="name" class="col-lg-2 control-label">z2</label>
<input id="z2" type="text">
<label for="name" class="col-lg-2 control-label">retailer</label>
<input id="retailer" type="text">
<label for="name" class="col-lg-2 control-label">value</label>
<input id="value" type="text">
<label for="name" class="col-lg-2 control-label">x</label>
<input id="x" type="text">
<label for="name" class="col-lg-2 control-label">y</label>
<input id="y" type="text">
<label for="name" class="col-lg-2 control-label">z</label>
<input id="z" type="text">
<label for="name" class="col-lg-2 control-label">shopper</label>
<input id="shopper" type="text">
<button id="button">Push Data</button>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script>
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());
});
</script>
</body>
</html>
Entschuldigung, mein ABI ist zu lang ...
versuchen testrpc --gas-limit 4600000
.
Denken Sie daran, dass testrpc in ganache-cli geändert wurde. ich renneganache-cli --gas-limit 4600000
Stellen Sie außerdem sicher, dass truffle.js konfiguriert ist. Sie können den Gaspreis und den Gaspreis ändern.
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "0",
gas: 10000000,
gasLimit: 10000000
},
}
Die SendCoin-Methode verbraucht 102912 Einheiten. Ich werde Ihnen vorschlagen, die Funktion zu verwenden estimateGas()
. Es wird zurückgegeben, wie viel Gas für eine bestimmte Eingabe verbraucht wird.
Siehe unten geänderter Code:
$("#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});
});
Ich schlage Ihnen vor, asynchrone Methoden zu verwenden. MetaMask führt keine Synchronisierungsmethoden aus.
gute Stimmung
function SendCoin
!!!Yohan
gute Stimmung
testrpc --gasLimit=0xfffffffffff --account=0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef,1000000000000000000000000000000000000000
(und stellen Sie sicher, dass Sie mit einem eindeutigen Schlüssel replizieren,--account=...
je nachdem, wie viele Konten Sie in Ihren Tests verwenden).Yohan