2

It seems I have a bit of trouble deploying a contract to testnet through infura

this is my code:

var Web3 = require('web3');

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

var account = web3.eth.accounts.privateKeyToAccount('5e8bdde40096190506b3182c29aaf068ef5ff3b0dc989ee7e0874ca6873b9fe5');

var _randomSeed = 12; var myContractInstance = new web3.eth.Contract([...]);

myContractInstance.deploy({
     data: '0x...',
     arguments:[_randomSeed]  }).send({
    from: account.address//,
    // gas: 1500000,
    // gasPrice: '30000000000000' 
}, function(error, transactionHash){ console.log(error, transactionHash); })
        .on('error', function(error){ console.log(error); })
        .on('transactionHash', function(transactionHash){ console.log(transactionHash); })
        .on('receipt', function(receipt){
            console.log(receipt.contractAddress) // contains the new contract address
        })
        .on('confirmation', function(confirmationNumber, receipt){ console.log(confirmationNumber, receipt); })
        .then(function(newContractInstance){
            console.log(newContractInstance.options.address) // instance with the new contract address
        });

I am able to get the balance of an address so it connects to the node but I get this error when I do .send() after .deploy()

Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (E:\workspace\Ethereum\DeployContract\node_modules\web3\packages\web3-core-helpers\src\errors.js:42:16)
    at XMLHttpRequest.request.onreadystatechange (E:\workspace\Ethereum\DeployContract\node_modules\web3\packages\web3-providers-http\src\index.js:60:32)
    at XMLHttpRequestEventTarget.dispatchEvent (E:\workspace\Ethereum\DeployContract\node_modules\web3\packages\web3-providers-http\node_modules\xhr2\lib\xhr2.js:64:18)
    at XMLHttpRequest._setReadyState (E:\workspace\Ethereum\DeployContract\node_modules\web3\packages\web3-providers-http\node_modules\xhr2\lib\xhr2.js:354:12)
    at XMLHttpRequest._onHttpResponseEnd (E:\workspace\Ethereum\DeployContract\node_modules\web3\packages\web3-providers-http\node_modules\xhr2\lib\xhr2.js:509:12)
    at IncomingMessage.<anonymous> (E:\workspace\Ethereum\DeployContract\node_modules\web3\packages\web3-providers-http\node_modules\xhr2\lib\xhr2.js:469:24)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9) undefined
Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (E:\workspace\Ethereum\DeployContract\node_modules\web3\packages\web3-core-helpers\src\errors.js:42:16)
    at XMLHttpRequest.request.onreadystatechange (E:\workspace\Ethereum\DeployContract\node_modules\web3\packages\web3-providers-http\src\index.js:60:32)
    at XMLHttpRequestEventTarget.dispatchEvent (E:\workspace\Ethereum\DeployContract\node_modules\web3\packages\web3-providers-http\node_modules\xhr2\lib\xhr2.js:64:18)
    at XMLHttpRequest._setReadyState (E:\workspace\Ethereum\DeployContract\node_modules\web3\packages\web3-providers-http\node_modules\xhr2\lib\xhr2.js:354:12)
    at XMLHttpRequest._onHttpResponseEnd (E:\workspace\Ethereum\DeployContract\node_modules\web3\packages\web3-providers-http\node_modules\xhr2\lib\xhr2.js:509:12)
    at IncomingMessage.<anonymous> (E:\workspace\Ethereum\DeployContract\node_modules\web3\packages\web3-providers-http\node_modules\xhr2\lib\xhr2.js:469:24)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)
Unhandled rejection Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (E:\workspace\Ethereum\DeployContract\node_modules\web3\packages\web3-core-helpers\src\errors.js:42:16)
    at XMLHttpRequest.request.onreadystatechange (E:\workspace\Ethereum\DeployContract\node_modules\web3\packages\web3-providers-http\src\index.js:60:32)
    at XMLHttpRequestEventTarget.dispatchEvent (E:\workspace\Ethereum\DeployContract\node_modules\web3\packages\web3-providers-http\node_modules\xhr2\lib\xhr2.js:64:18)
    at XMLHttpRequest._setReadyState (E:\workspace\Ethereum\DeployContract\node_modules\web3\packages\web3-providers-http\node_modules\xhr2\lib\xhr2.js:354:12)
    at XMLHttpRequest._onHttpResponseEnd (E:\workspace\Ethereum\DeployContract\node_modules\web3\packages\web3-providers-http\node_modules\xhr2\lib\xhr2.js:509:12)
    at IncomingMessage.<anonymous> (E:\workspace\Ethereum\DeployContract\node_modules\web3\packages\web3-providers-http\node_modules\xhr2\lib\xhr2.js:469:24)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

Do you have any idea why this happens or how can I solve it?

0

try adding your account to the in-memory wallet using your private key or the account object you get from privateKeyToAccount():

web3.eth.accounts.wallet.add(privateKey || account)

console.log(web3.eth.accounts.wallet.length) //=> 1

See the Web3 1.0 docs for more info

| improve this answer | |
0

Deploying via Infura can be very tedious at time.

Since you are trying to deploy on Rinkeby, should be easier with a local node at your end. Both Geth and Parity are quick to sync over Rinkeby (use fast option on Geth and warp option on Parity).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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