-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add snippet to check cUSD balance
- Loading branch information
1 parent
3f3be87
commit 3b97743
Showing
7 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const STABLE_TOKEN_ADDRESS = "0x765DE816845861e75A25fCA122bb6898B8B1282a"; | ||
|
||
module.exports = { | ||
STABLE_TOKEN_ADDRESS, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const ethers = require("ethers"); | ||
const StableToken = require("@celo/abis/StableToken.json"); | ||
const { STABLE_TOKEN_ADDRESS } = require("../constants"); | ||
|
||
const { Contract, utils } = ethers; | ||
const { formatEther } = utils; | ||
|
||
async function checkCUSDBalance(provider, address) { | ||
const StableTokenContract = new Contract( | ||
STABLE_TOKEN_ADDRESS, | ||
StableToken.abi, | ||
provider | ||
); | ||
|
||
let balanceInBigNumber = await StableTokenContract.balanceOf(address); | ||
|
||
let balanceInWei = balanceInBigNumber.toString(); | ||
|
||
let balanceInEthers = formatEther(balanceInWei); // Ether is a unit = 10 ** 18 wei | ||
|
||
return balanceInEthers; | ||
} | ||
|
||
module.exports = { | ||
checkCUSDBalance, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
"author": "Harpal Jadeja <[email protected]>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@celo/abis": "^9.0.6", | ||
"ethers": "5.7.2", | ||
"viem": "^1.19.9" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const { getContract, formatEther } = require("viem"); | ||
const StableToken = require("@celo/abis/StableToken.json"); | ||
const { STABLE_TOKEN_ADDRESS } = require("../constants"); | ||
|
||
async function checkCUSDBalance(publicClient, address) { | ||
let StableTokenContract = getContract({ | ||
abi: StableToken.abi, | ||
address: STABLE_TOKEN_ADDRESS, | ||
publicClient, | ||
}); | ||
|
||
let balanceInBigNumber = await StableTokenContract.read.balanceOf([ | ||
address, | ||
]); | ||
|
||
let balanceInWei = balanceInBigNumber.toString(); | ||
|
||
let balanceInEthers = formatEther(balanceInWei); | ||
|
||
return balanceInEthers; | ||
} | ||
|
||
module.exports = { | ||
checkCUSDBalance, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,11 @@ | |
resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.10.0.tgz#d2a39395c587e092d77cbbc80acf956a54f38bf7" | ||
integrity sha512-nA9XHtlAkYfJxY7bce8DcN7eKxWWCWkU+1GR9d+U6MbNpfwQp8TI7vqOsBsMcHoT4mBu2kypKoSKnghEzOOq5Q== | ||
|
||
"@celo/abis@^9.0.6": | ||
version "9.0.6" | ||
resolved "https://registry.yarnpkg.com/@celo/abis/-/abis-9.0.6.tgz#3586f578394cb0408f17335cdaedf98fd9f47d7c" | ||
integrity sha512-w/zQWAnJMUfthiFyzUoSKgZ1DQDKjXaSmImwGRDi6U9SPyEx5rWsHm7tsoVXoxYzAdPbtpkeFykQPvPqCJfHmA== | ||
|
||
"@ethersproject/[email protected]", "@ethersproject/abi@^5.7.0": | ||
version "5.7.0" | ||
resolved "https://registry.yarnpkg.com/@ethersproject/abi/-/abi-5.7.0.tgz#b3f3e045bbbeed1af3947335c247ad625a44e449" | ||
|