'Getting an error when calling a function of a smart contract using ethers.js

I deployed this(https://github.com/selimerunkut/bep20_NNN) token on binance smart chain testnet. I'm trying to call the changeAdmin function of this contract using etherjs but getting an error.

the command that I execute yarn hardhat run --network testnet scripts/bypass.js

hardhat.config.js

.....testnet: {
  url: "https://data-seed-prebsc-1-s1.binance.org:8545",
  chainId: 97,
  gasPrice: 20000000000,
},......

the script

const ethers = require('ethers')


async function main() {
    let network = 'https://data-seed-prebsc-1-s1.binance.org:8545/'
    let provider = ethers.getDefaultProvider(network)


    let privKey = "PRIVATE-KEY"
    let wallet = new ethers.Wallet(privKey, provider)

    let contractAddr = "0x066229c2D5E3673186b756a6c1f3C8689560B474" 
    let contractABI = ABI-OF-THE-CONTRACT
    let contract = new ethers.Contract(contractAddr, contractABI, provider)


    let contractWithWallet = contract.connect(wallet)
    let newOwnerAddr = "0xCc2c513ef320db14fc01b4a828EF548DAfF51429"
    let txResponse= await  contractWithWallet.changeAdmin(newOwnerAddr)
    let txReceipt = await txResponse.wait()
    console.log(txReceipt)


}

main()
    .catch((error) => {
        console.error(error)
        process.exit(1)
    })

THE ERROR

reason: 'cannot estimate gas; transaction may fail or may require manual gas limit', code: 'UNPREDICTABLE_GAS_LIMIT', Thanks in advance, have a nice day :)



Solution 1:[1]

It looks as if you may not have realized you are trying to execute contract.estimateGas.changeAdmin() instead of: contract.methods.changeAdmin().send({from: WALLET}). Could have been a typo when you were going through creating your script.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1