如何从UI调用approve()?

问题描述 投票:0回答:1

我需要从我的UI调用批准函数,以便可以在自己的智能合约中使用某个ERC20令牌。

我的代码如下:

// Gets the amount of token that user wants to have approved    
function getData() {
      var a = document.getElementById("amount").value;
      var b = a * 0.1;
      var c = a - b;
      document.getElementById("receive").innerHTML = c;
    };
    // calls the approve function
    function approve(){
      web3.eth.Contract.defaultAccount
      agiContract.defaultAccount // on contract instance


      var a = document.getElementById("amount").value;
      var agiContract = new web3.eth.Contract(agiabi,agiContractAddress);
      agiContract.methods.approve("0xE462CbEE0cd420f6c199B0194B1D8D93Fb5e7720", a).send();
    };
How can I make the approve function work?

Error ist this

exchange.js:81 Uncaught TypeError: Cannot read property 'defaultAccount' of undefined
    at approve (exchange.js:81)
    at HTMLButtonElement.onclick 
solidity web3js metamask
1个回答
0
投票

似乎在实例化合同之前,您是指agiContract.defaultAccount

© www.soinside.com 2019 - 2024. All rights reserved.