Contract approval

1. EVM Chain

This example uses the BSC chain USDT to apprive the contract 0xe5934c17cf172b83a4f5f4f8a94385ec0ef48537

Determine whether to approve and if gas is sufficient

// isApproved example
// USDT(BSC)  0x55d398326f99059ff775485246999027b3197955
 import { ethers } from "ethers";
 import abi from './abi'  // For details on the abi file, see the CrossChainXAbi.json file above
 import BigNumber from 'bignumber.js'

 const walletAddress = '0x6F14653a91AC36935bdB15db6ccC66dC57593653' // wallet address
 const contractAddress = '0x733dab9e78b67e1d4ccd1c2066f006d5eddf25be' //contract address
 const tokenContract = '0x55d398326f99059ff775485246999027b3197955' //token contract
 const provider = new ethers.providers.Web3Provider(window.ethereum, "any")
 const contract = new ethers.Contract(tokenContract, abi, provider)
 const fromNumber = 100 // 100 as a comparison quantity
 contract
  .allowance(walletAddress, contractAddress)
  .then((allowAmt) => {
    const num = new BigNumber(
     ethers.utils.formatUnits(allowAmt, 18),
    )
    const fromTokenNum = new BigNumber(fromNumber)
    console.log(num.toString())
    console.log(fromTokenNum.toString())
    if (num.gt(fromTokenNum)) {
        console.log('don`t need Approved')
    } else {
        console.log('need Approved')
    }
  })
  .catch( err => {
    //console.log(err)
  })

approval code example

2、TRON Chain

This example uses the TRON chain USDT to apprive the contract TEorZTZ5MHx8SrvsYs1R3Ds5WvY1pVoMSA

Determine whether to approve and if gas is sufficient

approval code example

send coins code example

Last updated