Using the pyrin.Wallet() we can connect and create or import wallet and interact with the account.

Simple account instance example

async def wallet_example():
    wallet = pyrin.Wallet()
    await wallet.connect()
    # Account instance
    account = await wallet.create()

Immediately we are able to get the public address:

print(account.receive_address) # pyrin:qpvdcqyvlvkn3w5npdzk5mtptft5d6n3tfdh06hf32kxtvm9sp6wxkddm6p45

Interacting with the wallet

Any interaction with the RPC connection and blockchain itself require first to start internal processor and other tasks, to do so we call the async account.init():

await account.init()

Now we can print the current balance as interval:

async def wallet_example():
    wallet = pyrin.Wallet()
    await wallet.connect()
    account = await wallet.create()
    await account.init()
    while True:
        b = account.balance()
        print(b.mature, b.pending, b.outgoing)
        await asyncio.sleep(1)

Importing existing wallet

wallet = pyrin.Wallet()
success = await wallet.connect()
account = await wallet.import_account("custom elevator under van sunset reason much puppy valley speak coffee debris loud shoot maple govern evoke junior view duty elder cabin swap spray")

Change Address


Send PYI

Minimum sending of PYI is 0.2 due to the storage mass calculation, more into can be found at KIP9

# Creating or importing an account
await account.init() # Make sure we initialize the proper blockchain tracking of the account

result = await account.send("pyrin:qpwx6a66j38gqgxcvc74ts77fkxhdzdunl6uhvdcplp0cgvvwrx86n2zl67u0", 0.1, 0.2) # address, priority fee, amount
print("aggregated_utxos", result.aggregated_utxos) # 1
print("aggregated_fees", result.aggregated_fees) # 10052054
print("number_of_generated_transactions", result.number_of_generated_transactions) # 1
print("final_transaction_amount", result.final_transaction_amount) # 20000000
print("final_transaction_id", result.final_transaction_id) # 996ad73da7427fa732555139380f46ce54f92d1469a70b5fc52329e389346abf


await account.init()
fee = await account.estimate(0.1, 0.2) # priority fee, amount
print("fee", fee) # 10052054


Listen to changes to dda score, balance etc

DDA Score

await account.init()

def dda_score(data):
    print(f"dda_score: {data}")

await account.listen("dda-score", dda_score)


await account.init()

def balance(b):
          print("balance:", b.mature, b.pending, b.outgoing)
          # b.mature_utxo_count
          # b.pending_utxo_count
          # b.stasis_utxo_count

await account.listen("balance", balance)

Last updated