Skip to content

Instantly share code, notes, and snippets.

@normanlmfung
Created October 21, 2022 03:17
Show Gist options
  • Save normanlmfung/dc6630e5b8fbfd4a06d378b776197549 to your computer and use it in GitHub Desktop.
Save normanlmfung/dc6630e5b8fbfd4a06d378b776197549 to your computer and use it in GitHub Desktop.
hello aptos
from aptos_sdk.account import Account, AccountAddress
from aptos_sdk.client import RestClient, FaucetClient
from aptos_sdk.ed25519 import PrivateKey
NODE_URL = "https://fullnode.devnet.aptoslabs.com/v1"
FAUCET_URL = "https://tap.devnet.prod.gcp.aptosdev.com"
wallet_address = "xxx"
private_key = "xxx"
rest_client = RestClient(NODE_URL)
pk = PrivateKey.from_hex(private_key)
addr = AccountAddress.from_hex(wallet_address)
acc = Account(addr, pk)
acc_balance = rest_client.account_balance(acc.address())
print(f"acc_balance: {acc_balance}")
'''
If you're on "testnet", you can use https://aptoslabs.com/testnet-faucet to fund your account.
If you're on "devnet", try below.
'''
faucet_client = FaucetClient(FAUCET_URL, rest_client)
for i in range(100):
try:
faucet_client.fund_account(acc.address(), 1_000_000_000) # That's one APT, which is maximum how much you can add each call.
except:
pass #swallow
acc_balance = rest_client.account_balance(acc.address())
print(f"acc_balance: {acc_balance} YOU ARE RICH!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment