I'm using this code from Onboard.js:
import ethers from 'ethers'
import erc20 from './erc20'
function tokenBalance({ tokenAddress, minimumBalance, tokenName }) {
let ethersProvider;
let tokenContract;
return async stateAndHelpers => {
const {
wallet: { provider },
address,
BigNumber
} = stateAndHelpers;
if (!tokenContract) {
ethersProvider = new ethers.providers.Web3Provider(provider);
tokenContract = new ethers.Contract(tokenAddress, erc20, ethersProvider);
}
const tokenDecimals = await tokenContract.decimals();
const divideBy = new BigNumber(10).pow(tokenDecimals);
const tokenBalanceResult = await tokenContract
.balanceOf(address)
.then(res => res.toString());
const tokenBalance = new BigNumber(tokenBalanceResult).div(divideBy);
if (tokenBalance.lt(minimumBalance)) {
return {
heading: `Get Some ${tokenName}`,
description: `You need to have at least ${minimumBalance} ${tokenName} to interact with this Dapp. Send some more ${tokenName} to this address or switch to another address that has a higher ${tokenName} balance.`,
eventCode: "tokenBalance",
icon: `
<svg
height="18"
viewBox="0 0 429 695"
width="18" xmlns="http://www.w3.org/2000/svg"
>
<g
fill="currentColor"
fill-rule="evenodd"
>
<path d="m0 394 213 126.228516 214-126.228516-214 301z"/>
<path d="m0 353.962264 213.5-353.962264 213.5 353.962264-213.5 126.037736z"/>
</g>
</svg>
`
};
}
};
}
const defaultWalletChecks = [
{ checkName: 'connect' },
{ checkName: 'network' },
{ checkName: 'balance', minimumBalance: '100000' }
]
const tokenBalanceCheck = tokenBalance({tokenAddress: '0x6b175474e89094c44da98b954eedeac495271d0f', tokenName: 'Dai', minimumBalance: 5})
const onboard = Onboard({
//... other options
walletCheck: [...defaultWalletChecks, tokenBalanceCheck]
})
And I'm getting this error:
Error: call revert exception (method="balanceOf(address)", errorSignature=null, errorArgs=[null], reason=null, code=CALL_EXCEPTION, version=abi/5.1.0)
The only difference is that I'm using an erc20 abi format I got externally. I've also checked that my network and my addresses were correct. Not sure why I'm getting that error so any help would be appreciated!