Fehler: Ungültige JSON-RPC-Antwort: „“ bei Verwendung von infura

Mein Code:

const contract = require('truffle-contract');
const fs = require('fs');
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');

const fileContents = fs.readFileSync('../../build/contracts/CoincodeToken.json', 'utf8');
const coincodeArtifacts = JSON.parse(fileContents);
const coincode = contract(coincodeArtifacts);

const walletMnemonic = 'god wwe lawsuit tiny mobile door raccoon chaos foil someone city siege';
const walletAPIUrl = 'https://rinkeby.infura.io/Fwp5nmX6Ze5FouVcBlHs';

const provider = new HDWalletProvider(walletMnemonic, walletAPIUrl);

const web3 = new Web3(provider);
coincode.setProvider(new Web3.providers.HttpProvider("https://rinkeby.infura.io/Fwp5nmX6Ze5FouVcBlHr"));

web3.eth.getAccounts(function (err, ac) {
    if (err != null) {
        console.error("There was an error fetching accounts.");
        return;
    }
    if (ac.length == 0) {
        console.error("Couldn't get any accounts! Make sure ethereum client is configured correctly.");
        return;
    }
    var accounts = ac;
    var account = accounts[0];
    web3.eth.defaultAccount = account;
    console.log(web3.eth.defaultAccount);

    coincode.deployed().then(function (instance) {
        return instance.transfer('0xa977575a23c55aaa992cfa585c2efc15b404259b', 2000000000000000000000, {from:account}).then(function (value) {
            value = value / 1000000000000000000;
            console.log("Printing value: " + value);
        });
    }).catch(function (e) {
        console.error(e);
    });
});

Ausgang:

0x24a60d3abe605a0ffc2852863eba5e517e5a4fc4

Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (/home/pravin-coincode/infura/node_modules/web3/lib/web3/errors.js:38:16)
    at XMLHttpRequest.request.onreadystatechange (/home/pravin-coincode/infura/node_modules/web3/lib/web3/httpprovider.js:125:24)
    at XMLHttpRequestEventTarget.dispatchEvent (/home/pravin-coincode/infura/node_modules/xhr2/lib/xhr2.js:64:18)
    at XMLHttpRequest._setReadyState (/home/pravin-coincode/infura/node_modules/xhr2/lib/xhr2.js:354:12)
    at XMLHttpRequest._onHttpResponseEnd (/home/pravin-coincode/infura/node_modules/xhr2/lib/xhr2.js:509:12)
    at IncomingMessage.<anonymous> (/home/pravin-coincode/infura/node_modules/xhr2/lib/xhr2.js:469:24)
    at IncomingMessage.emit (events.js:187:15)
    at endReadableNT (_stream_readable.js:1090:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
Sie verwenden zwei Anbieter. Zuerst verwenden Sie HDWalletProvider, wenn Sie web3 erstellen, aber Sie überschreiben Ihren Vertrag mit einem normalen HttpProvider.

Antworten (2)

Wenn ich mir Ihre Seed-Phrase ansehe, denke ich nicht, dass Gott und WWE oder auf der Liste der gültigen Seed-Wörter stehen. https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt

Ich ändere dies manuell, weil es privat ist. Aber ich werde mit dem ursprünglichen Seed ausgeführt

Überprüfen Sie Ihren Anbieter noch einmal, da Sie ihn zweimal definieren und das letzte Zeichen in der URL abweicht