0

My account has enough ether to make a transaction. How do i call a payable function that is written in solidity? I tried by calling like this

    const Web3 = require('web3');

const HDWalletProvider = require('truffle-hdwallet-provider');
const campaign = require('./build/CampaignFactory');



const provider = new HDWalletProvider(
  '12 word mnemonic',
  'https://rinkeby.infura.io/authid',
);
const web3 = new Web3(provider);
const accounts = await web3.eth.getAccounts();
      await campaign.methods.contribute().send({
        from: accounts[0],
        value: web3.utils.toWei(this.state.value, 'ether')
      });

But i am getting this error "intrinsic gas too low". Earlier with metamask extension it used to ask for confirmation if i click submit from metamask then the transaction used to get success. Now since i removed metamask extenstion i am getting this error. I want to make this transaction without metamask. Is it possible to do?

  • Check for default gas price and gas limit, as metamask might be putting default gas limit and price for you. var gasPrice = web3.eth.gasPrice; console.log(gasPrice.toString(10)); – kherwa Mar 30 '18 at 14:22
  • Kherwa awesome thanks for the answer. Now i can able to make transactions without metamask. – Trinu Mar 30 '18 at 14:40
0

you can pass gasLimit and gasPrice explicitly also.

await campaign.methods.contribute().send({
            from: accounts[0],
            value: web3.utils.toWei(this.state.value, 'ether'),
            gas: 'gasLimit',
            gasPrice: 'gasPriceInWei'
          });
1

I solved it by just passing gas like this.

const accounts = await web3.eth.getAccounts();
  await campaign.methods.contribute().send({
    from: accounts[0],
    value: web3.utils.toWei(this.state.value, 'ether'),
    gas: '1000000'
  });

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.