0

In my project, I am doing a transaction by using

ethereum.send({ })

method from web3 in javascript using metamask. After the transaction completes I want to display the link to the user in label which will redirect to the Etherscan website with the current transaction details such that user can view transaction details on clicking that. Like this link : https://kovan.etherscan.io/tx/0x5ffc0cd24cc1bba25df0d971ae4cbabbf0979aa76909272387bda6a0ab96dd64. Currently I am using Kovan Testnet Network. How to get this complete link?

1

When sending transaction you can use events to get the transaction hash and using the transaction hash can create and redirect the user to the etherscan.

This example is using the window object

 myContract.methods.myMethod(123).send({from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe'})
.on('transactionHash', (hash) => {
 // similar behavior as an HTTP redirect
window.location.replace("https://kovan.etherscan.io/tx/" + transactionHash);

// similar behavior as clicking on a link
window.location.href = "https://kovan.etherscan.io/tx/" + transactionHash;
})

If using React, Angular or Vue, you can redirect using router

  • Yes currently I am doing this only but Is there any way so that we can get the complete link? It will be useful in case we change the network. Otherwise, every time I need to change the code – Varsh May 7 at 7:46
  • There is none currently, but you can write up your own function that can return the url based on the network ID – Hamza Ahmed May 7 at 7:52

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.