1

For a web application i stored the transaction id of an activity. if the user retry the transaction with a higher gas price in metamask(in case of the transaction take too long, metamask gives this option), is there is any possibility to replace the current transaction id that i stored with new one. how can detect this retry. is there is any web3 method for this?

1 Answer 1

0

If you want the same transaction to be carried out but just with a higher gas price, you won't need to replace the transaction ID as that doesn't change.

Calling a function in your front end with web3.js you would use this piece of code

   function functionYouWantToCall() {
        web3.eth.getAccounts(function(error, result) {
        web3.eth.sendTransaction(
            {from:web3.eth.accounts[0],
            to: YourContractAddress,
            value:  "0", 
            data: "0xTheHashOfTheFuctionYouWantToCall"
                }, function(err, result) {
          if (!err)
            console.log(error); 
        });
    });

    } 

To find the information you should put in the data field, go to Remix and then on the run tab select details, scroll down to function hashes and select paste in the hash of the function you wish to call with 0x in front of it. Also make sure to enter your own contracts address in the contract address feild

4
  • but the retry generates new transaction id, and the old one will always in pending state, after some time this id will delete from etherscan, any solution to get the new id?
    – Akash
    Commented Mar 1, 2018 at 7:33
  • Are you doing this with a smart contract that's been uploaded to the blockchain?
    – JAG
    Commented Mar 1, 2018 at 7:34
  • yes. doing with an uploaded smartcontract
    – Akash
    Commented Mar 1, 2018 at 8:02
  • I've updated my answer, hopefully this should help
    – JAG
    Commented Mar 1, 2018 at 8:19

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.