0

Description

I'm trying to deploy a contract to rinkeby network, but everytime I like to deploy the contract it throwing error as invalid sender.

Compile code

const path = require('path');
const fs = require('fs');
const solc = require('solc');

const contractFile = 'xxx.sol';

const lotteryPath = path.resolve(__dirname, 'contracts', contractFile);
const source = fs.readFileSync(lotteryPath, 'utf8');

const input = {
    language: 'Solidity',
    sources: {
        [contractFile]: {
            content: source
        }
    },
    settings: {
        outputSelection: {
            '*': {
                '*': ['*']
            }
        }
    }
}

const compiled_contract = JSON.parse(solc.compile(JSON.stringify(input)));

const interface = compiled_contract.contracts[contractFile]['XXX'].abi;
const bytecode = compiled_contract.contracts[contractFile]['XXX'].evm.bytecode.object;

module.exports = { interface, bytecode };

Deploy Code

const HDWalletProvider = require('@truffle/hdwallet-provider');
const Web3 = require('web3');

const { interface, object: bytecode } = require('./compile');

const provider = new HDWalletProvider(
  'mnemonic phrases...',
  'https://rinkeby.infura.io/v3/bba91a6c349c44afbde264a1bda1af75'
);

const web3 = new Web3(provider);

(async () => {
  const accounts = await web3.eth.getAccounts();

  const result = await new web3.eth.Contract(interface)
    .deploy({ data: bytecode })
    .send({ from: accounts[0], gas: '1000000' }); 

  console.log('interface', interface);
  console.log('Contract deployed to', result.options.address);

})();

Versions

  • "@truffle/hdwallet-provider": "^1.0.19"

  • "web3": "^1.2.1"

  • "solc": "^0.5.11",


Deploy command:

"start": "node deploy.js"

Error logs

Attempting to deploy from account [ '0x.....' ]
Error: invalid sender
at D:\projects\blockchain\demo\node_modules\web3-provider-engine\subproviders\provider.js:18:36
at XMLHttpRequest.request.onreadystatechange (D:\projects\blockchain\demo\node_modules\web3-providers-http\src\index.js:96:13)
at XMLHttpRequestEventTarget.dispatchEvent (D:\projects\blockchain\demo\node_modules\xhr2-cookies\dist\xml-http-request-event-target.js:34:22)
at XMLHttpRequest._setReadyState (D:\projects\blockchain\demo\node_modules\xhr2-cookies\dist\xml-http-request.js:208:14)
at XMLHttpRequest._onHttpResponseEnd (D:\projects\blockchain\demo\node_modules\xhr2-cookies\dist\xml-http-request.js:318:14)
at IncomingMessage. (D:\projects\blockchain\demo\node_modules\xhr2-cookies\dist\xml-http-request.js:289:61)
at IncomingMessage.emit (events.js:203:15)
at endReadableNT (_stream_readable.js:1145:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
Error: invalid sender
at D:\projects\blockchain\demo\node_modules\web3-provider-engine\subproviders\provider.js:18:36
at XMLHttpRequest.request.onreadystatechange (D:\projects\blockchain\demo\node_modules\web3-providers-http\src\index.js:96:13)
at XMLHttpRequestEventTarget.dispatchEvent (D:\projects\blockchain\demo\node_modules\xhr2-cookies\dist\xml-http-request-event-target.js:34:22)
at XMLHttpRequest._setReadyState (D:\projects\blockchain\demo\node_modules\xhr2-cookies\dist\xml-http-request.js:208:14)
at XMLHttpRequest._onHttpResponseEnd (D:\projects\blockchain\demo\node_modules\xhr2-cookies\dist\xml-http-request.js:318:14)
at IncomingMessage. (D:\projects\blockchain\demo\node_modules\xhr2-cookies\dist\xml-http-request.js:289:61)
at IncomingMessage.emit (events.js:203:15)
at endReadableNT (_stream_readable.js:1145:12)
at process._tickCallback (internal/process/next_tick.js:63:19)

BR, Igor

1

Try:

    const contract = await new web3.eth.Contract(JSON.parse(interface))
      .deploy( { data:"0x"+bytecode} )
      .send( { gas: '300000', gasPrice: 10, from:accounts[0]});

Otherwise please make sure that your accounts array includes actual values.

  • Again I have the same issue. I'm stuck for some time with this issue and i'm not sure how to handle it. The interface is parsed in the compile file. In the accounts[0] I have only my metamaska= public address. I've updated the question with the compile code. This code works when do the tests with ganache. – Игор Ташевски Oct 17 at 17:48
  • Ok. But how about the bytecode did you try appending "0x" – Niklas Feurstein Oct 17 at 18:02
  • I've has some issue on infura and set the secret checkbox, but now when the deploying starts, nothing shows on the console. The code is wrapped in try catch, but nothing appears, nor in try or the catch block. – Игор Ташевски Oct 17 at 19:53
  • If the project secret in infura is selected than the nothing is shown on the console, otherwise i'm getting invalid sender :/ – Игор Ташевски Oct 17 at 20:02
  • Today, i'm getting error: insufficient funds for gas * price + value. – Игор Ташевски Oct 18 at 21:17

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.