简体   繁体   中英

How can I get the web3 contract address before confirming transaction in the browser or chrome extension?

Let's say I want to buy an NFT and my Metamask popup opens asking me to confirm the transaction. There you can see the contract address... but how can I access this contract address (just retrieve the value, not change it :) ) programmatically using javascript in the browser or an extension?

Hey for getting the contract address on your console just include this code in the .sol file and also update the abi of the code .

    function get() view public returns(address ){
        return address(this);
    }

And in the frontend to intract with your smart contract and for getting the result in the console include this in your index.js file

              contract.methods.get().call().then(function (resp){
               console.log(resp);
              });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM