I have the call working for a non-gas execution.

This code below does not seem to run. Should I add account in the call?

let addContract = async (inputValue) => {
    var abi=

    var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/'));
    var contractaddress= "0xb316b4bf742818d3fb97586a2f3aea361b240f30";

    var hashVal = web3.utils.sha3(inputValue);

    let commodityContract = new web3.eth.Contract(abi, contractaddress);
  //  let newContract =   commodityContract.at(this.state.contractAddress);
  //  this.setState({commodityContract: commodityContract});
    web3.eth.defaultAccount = web3.eth.coinbase;
  //  var testResult = commodityContract.contracts(test1);
    var result='';
       (result) => console.log(result)


  • You probably want send, not call. – user19510 Apr 2 '18 at 2:20
  • Yes send and also the account to charge the gas should be given. I am unsure how that is done. – Trevor Lee Oakley Apr 2 '18 at 5:21
  • I believe web3.eth.defaultAccount should take care of that. You can use send({ from: '0x123abc...' }) if you want to override the default. – user19510 Apr 2 '18 at 5:22
  • I am just checking into this. I was wondering about security. I am using Ropsten. So I am unsure what the default account will be. The system needs to prevent theft so there must be some kind of key system. – Trevor Lee Oakley Apr 2 '18 at 5:40
  • Oh, sorry, I see you're using Infura. You can't just use send then, because Infura doesn't know the private key for your account. (That has nothing to do with Ropsten vs. the main network, it's just that you're using a public node.) If you want to use a public node directly, you'll need to sign transactions locally (with a private key) and then send them via sendSignedTransaction. – user19510 Apr 2 '18 at 5:54

You can do it adding few parameters in call():

    const response2 = await contract.methods
            gasPrice : this.state.web3.utils.toWei("5", "gwei"), 
            gas : this.state.web3.utils.toWei("0.0000000000005", "ether")});
| 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.