TLDR我正在沙箱中运行Algorand PrivateNet。我想知道如何使用Python SDK for Algorand返回该网络上帐户的地址和余额。
更长的版本到目前为止,我一直在使用"./sandbox goal account list"
来查找Bash中的帐户地址和帐户余额,这将返回:
[离线] | I3CMDHG236HVBDMCKEM22DLY5L2OJ3CBRUDHG4VVFGEZ4QQR3X3KNHRMU | I3cMDHG236HV BDMCKEm22DLY5L20J3CBRUDG4PVVFGEZ4 QQR3X3kNHRMU8012889074131520 microAlgos | |
[离线] | 3NSWKJTYMW3PSZDIE6NCHMRTOZ24VY5G3OJNDSTYRVRXMZBZVPCGQHJJI | 3MSWKJTIMW3PSZdie6NCHMRToZ24Vy5G3OjnDSTYRVXMZBZVPGCQHJJI<1001611000000000微算法>||
[在线] | 5KLSI3AHMBBDALXBEO2HEA3PBBCBAYT4PIHCD3B25557WGWUZGRTQETPHQ |
出现上述问题是因为与./sandbox goal accounts list
一样,我试图返回KMD中本地拥有密钥的帐户,但我对索引器raw_details = indexer().accounts()
的调用返回了网络上的所有帐户。
要解决此问题,请从algosdk
库导入wallet
模块,而不是导入并使用v2client.indexer
模块。这些是必要的进口:
from algosdk import algod, kmd, wallet
然后设置到algord、kmd和钱包的连接:
# instatiate AlgodClient
def connect_to_network():
algod_address = "http://localhost:4001"
algod_token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
algod_client = algod.AlgodClient(algod_token, algod_address)
return algod_client
# instantiate KMDClient <--- this is used as a parameter when instantiating the Wallet Class.
def key_management():
kmd_address = "http://localhost:4002"
kmd_token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
kmd_client = kmd.KMDClient(kmd_token, kmd_address)
return kmd_client
#get wallet details
def wallet_details():
wallet_name = 'unencrypted-default-wallet'
password = ""
kmd_client = key_management()
return wallet.Wallet(wallet_name, password, kmd_client)
您现在可以返回KMD:中本地持有的帐户地址
keys = wallet_details().list_keys()
既然你有了地址,你就可以使用algord客户端返回每个地址的(Micro(Algo数量。