0

My 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);
    });
});

Output:

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)
1
  • You are using two providers first you use HDWalletProvider when creating web3 but you override in your contract with a normal HttpProvider.
    – Ismael
    Jul 8, 2018 at 2:24

2 Answers 2

0

Looking at your seed phrase, I don't think god and wwe or on the list of valid seed words. https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt

1
  • 1
    i manually change this because it is private.. but i'm execute with original seed
    – Rohit Sahu
    Aug 30, 2018 at 10:56
0

Double check your provider as you are defining it twice and the last character in the url differs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.