Skip to content

Instantly share code, notes, and snippets.

@dvush
Created September 17, 2020 18:26
Show Gist options
  • Save dvush/cf8b0e511be70a9f172a43cd2afb8d8f to your computer and use it in GitHub Desktop.
Save dvush/cf8b0e511be70a9f172a43cd2afb8d8f to your computer and use it in GitHub Desktop.
Get balance on contract
async function getBalanceOnContract(ethSigner: ethers.Signer, zksyncProvider: zksync.Provider, token: zksync.types.TokenLike) {
const tokenId = zksyncProvider.tokenSet.resolveTokenId(token);
const ABI = [{
"constant": true,
"inputs": [
{
"internalType": "address",
"name": "_address",
"type": "address"
},
{
"internalType": "uint16",
"name": "_tokenId",
"type": "uint16"
}
],
"name": "getBalanceToWithdraw",
"outputs": [
{
"internalType": "uint128",
"name": "",
"type": "uint128"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}]
const zksContract = new ethers.Contract(zksyncProvider.contractAddress.mainContract, ABI, ethSigner.provider);
return await zksContract.getBalanceToWithdraw(await ethSigner.getAddress(), tokenId);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment