简体   繁体   English

在浏览器或chrome扩展程序中确认交易之前如何获取web3合约地址?

[英]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.假设我想购买 NFT,我的 Metamask 弹出窗口打开,要求我确认交易。 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?在那里你可以看到合约地址......但是我如何在浏览器或扩展程序中使用 javascript 以编程方式访问这个合约地址(只是检索值,而不是更改它:))?

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 .嘿,在您的控制台上获取合约地址只需将此代码包含在 .sol 文件中,并更新代码的 abi。

    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并在前端引入您的智能合约并在控制台中获取结果,将其包含在您的 index.js 文件中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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