1

I'm a beginner in blockchain and facing a huge problem while deploying my smart contract with Truffle.

first my simple contract...

pragma solidity ^0.8.10;

contract Inbox{
    string public message;

constructor(string memory initialMessage){
    message = initialMessage;
}

function setMessage(string memory newMessage) public {
    message = newMessage;
}

}

then my deploy.js script, I'm using Rinkeby testnetwork/web3/truffle-hd-wallet.

const HDWalletProvider = require('@truffle/hdwallet-provider');
const Web3 = require('web3');
const { interface, bytecode } = require('./compile');

const provider = new HDWalletProvider(
  'My mnemonic',
  'https://rinkeby.infura.io/v3/MY-INFURA-PROJECT-ID'
);

const web3 = new Web3(provider);


const deploy = async () => {

  const accounts = await web3.eth.getAccounts();

  console.log('Attempting to deploy from account ', accounts[0] ); //working till here fine

  const result = await new web3.eth.Contract(interface)
   .deploy({data: '0x' + bytecode, arguments: ['Hi there!']}) 
   .send({gas: '5000000000', from: accounts[0]}); 

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

};

deploy();

I'm deploying like this but getting errors in number form and those numbers are flowing without stopping. Please help me. The error is given below in picture form because I'm unable to describe it in words.

the error.

{ code: -32000, message: 'insufficient funds for gas * price + value' }

My compile.js

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

const inboxPath = path.resolve(__dirname, 'contracts', 'inbox.sol');

const source = fs.readFileSync(inboxPath, 'utf-8');

var input = {
  language: 'Solidity',
  sources: {
    'inbox.sol' : {
        content: source
    }
  },
 settings: {
    outputSelection: {
        '*': {
            '*': [ '*' ]
        }
    }
   }
 }; 

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

 const interface = output.contracts['inbox.sol'].Inbox.abi;
 const bytecode = 
 output.contracts['inbox.sol'].Inbox.evm.bytecode.object;

 module.exports = {
     interface,
     bytecode
 };
5
  • 1
    Add the content of compile.js to the question. My guess that you are using a newer solc version and the compilation fails.
    – Ismael
    Commented Nov 21, 2021 at 16:58
  • yes I'm using the latest version
    – Adil Nehal
    Commented Nov 21, 2021 at 18:29
  • added compile.js
    – Adil Nehal
    Commented Nov 21, 2021 at 18:32
  • 1
    Perhaps silly question but have you funded your testnet address (via the Rinkeby faucet faucet.rinkeby.io ) ? Commented Nov 22, 2021 at 12:59
  • 1
    @AdilNehal The gas used is just too much try 5M,gas: "5000000".
    – Ismael
    Commented Nov 22, 2021 at 17:17

1 Answer 1

1

I solve this problem by getting test ethers in my rinkeby wallet and then transferring some ethers to the address from which I'm deploying the contract.

Your Answer

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

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