Fehler: „Ungültige JSON-RPC-Antwort“ beim Ausführen von „Schätzgas“ auf Infura

Warum erhalte ich eine Fehlermeldung, wenn ich eine Gasschätzung auf infura durchführe. Ich benutze web3 v1.0und hier ist mein Code:

let Web3 = require('web3'); 
var web3 = new Web3(new Web3.providers.HttpProvider('http://ropsten.infura.io/key'));

const account = '0x5561E1e11199317E2186.....';
const contractAddress = '0x72A0411ee2f3.....'; 

var tokenizeContract = new web3.eth.Contract( [ ...abi... ], '0x72A0411ee2f328E34AB8DE74e51820bC257ccDE5' ); 

const contractFunction = tokenizeContract.methods.setOrder(web3.utils.toHex('location'), web3.utils.toHex('productName'), web3.utils.toHex('customer'), 3000, 2, 6000, web3.utils.toHex('timestamp'));

contractFunction.estimateGas(function(error, gasAmount) {
    if(!error) {
        console.log(gasAmount);
    } 
    else {
        console.log(error);
    }
});

Das ist der Fehler:

Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (/home/user/code/project_poc/node_modules/web3-core-helpers/src/errors.js:42:16)
    at XMLHttpRequest.request.onreadystatechange (/home/user/code/project_poc/node_modules/web3-providers-http/src/index.js:73:32)
    at XMLHttpRequestEventTarget.dispatchEvent (/home/user/code/project_poc/node_modules/xhr2/lib/xhr2.js:64:18)
    at XMLHttpRequest._setReadyState (/home/user/code/project_poc/node_modules/xhr2/lib/xhr2.js:354:12)
    at XMLHttpRequest._onHttpRequestError (/home/user/code/project_poc/node_modules/xhr2/lib/xhr2.js:544:12)
    at ClientRequest.<anonymous> (/home/user/code/project_poc/node_modules/xhr2/lib/xhr2.js:414:24)
    at ClientRequest.emit (events.js:180:13)
    at Socket.socketErrorListener (_http_client.js:395:9)
    at Socket.emit (events.js:180:13)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at process._tickCallback (internal/process/next_tick.js:178:19)
Warum konvertieren Sie alle Ihre Parameter in Hex? Sie müssen dies nicht tun.
bytes32Denn die Variablen sind wie im Smart Contract definiert . Es gibt keine Möglichkeit, stringdie Eingabe zu verwenden, solidityoder gibt es eine Möglichkeit?
Du kannst natürlich Strings verwenden. Warum nicht? Sie werden nur Einschränkungen haben, können Sie Oo

Antworten (1)

Die Lösung in meinem Fall verwendet httpsanstelle von http:

var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/key'));