Last active
November 4, 2022 04:29
-
-
Save normanlmfung/8a9fa41ff8f0bc219cc40aa0652d4df4 to your computer and use it in GitHub Desktop.
aptos fetch coin balances
This file contains hidden or 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
NODE_URL = "https://fullnode.mainnet.aptoslabs.com/v1" | |
FAUCET_URL = "https://tap.devnet.prod.gcp.aptosdev.com" | |
wallet_address = None | |
private_key = None | |
rest_client = HoustonClient(NODE_URL) | |
pk = PrivateKey.from_hex(private_key) | |
addr = AccountAddress.from_hex(wallet_address) | |
acc = Account(addr, pk) | |
RESOURCE_TYPES = { | |
'APT' : { | |
'type' : '0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>', | |
'decimals' : 8 | |
}, | |
'USDC' : { | |
'type' : '0x1::coin::CoinStore<0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC>', | |
'decimals' : 6 | |
}, | |
'USDT' : { | |
'type' : '0x1::coin::CoinStore<0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT>', | |
'decimals' : 6 | |
} | |
} | |
balances = [] | |
for ccy in RESOURCE_TYPES: | |
resource_type = RESOURCE_TYPES[ccy]['type'] | |
rsp = rest_client.account_resource(acc.address(), resource_type) | |
if rsp: | |
ccy_balance = int(rsp['data']['coin']['value']) / (10 ** RESOURCE_TYPES[ccy]['decimals']) | |
entry = { | |
'ccy' : ccy, | |
'balance' : ccy_balance | |
} | |
balances.append(entry) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment