简体   繁体   中英

Approve transaction with BUSD in dapp with ethers.js

I am creating daap able to mint smart contract with BUSD. However, transfer still fail. I figured out that my BNB allocation can not automatically pay thought BUSD. I need to BUSD allow to make transaction with my allocation. According to BUSD smart contract there is function provided for it -> function approve(address _spender, uint256 _value) public whenNotPaused returns (bool).

However I was not able to efficiently receive output from it. I have tried to connect to transfer and receive data but without success.

  async approveBUSD(wallet, address, price) {
    let contract = new ethers.Contract(this.busd, busdAbi, this.provider);

    this.busdContract.on('Transfer',(from,to, value,event)=>{
      console.log({
        from: from,
        to:to ,
        value:value.toNumber(),
        data: event
      });
    });
  }

Any suggestion? Thanks...

 busdContract.approve(contractAddress, amount)
                    .then((txHash) => {
                        alert(txHash);
                    localStorage.setItem("txHash", txHash);
                    resolve(true);
                })
                    .catch((error) => {
                        alert(error);
                        resolve(false);
                    });

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