Wait for Transaction


Does the SDK offer a way to wait for a transaction to be mined and get its status(success/failed)?


1 Like

yes, but how it is specific to the sdk. for the python one there are 2 ways:

#!/usr/bin/env python
from aeternity.node import NodeClient

def main():
        tx_hash = "th_XWPEjQfF6PY27V2ruJgDeMkbHTScqyEkgQoPBF2DNSokRSW98"
        n = NodeClient(
            key_block_confirmation_num=10 # number of blocks for considering a block mined (default 3)
        # wait for a transaction to be included and confirmed
        # wait for a transaction to appear in the chain (no confirmations)
    except Exception as e:
        print(f"Error: {e}")

if __name__ == "__main__":
1 Like

Anyway in aepp-sdk-js, because I cannot find it?

Pretty sure @nduchak can give you an answer to this :slight_smile:


This is what I use to wait for tx to be mined:

async function waitMined(txHash) {
    return new Promise(async (resolve) => {
        client.poll(txHash).then(async _ => {
            client.getTxInfo(txHash).then(async (info) => {
                console.log(`\nTransaction ${txHash} mined! Status: ${info.returnType}`)

client in this case is a client instance initialized using aepp-sdk-js like so:

const { Universal: Ae, Crypto } = require('@aeternity/aepp-sdk')

client = await Ae({
    url: 'https://sdk-testnet.aepps.com/',
    internalUrl: 'https://sdk-testnet.aepps.com',
    keypair: Crypto.generateKeyPair(),
    networkId: 'ae_uat',
    compilerUrl: 'https://compiler.aepps.com'

So to check for transaction status you make this call:

await waitMined("th_....")

This is just a first thing that crossed my mind, maybe there are better ways to implement it but it works fine.


Great, thanks, i was also looking for this.

1 Like

Why not introduce it in the sdk, since everyone will need this?

@kraykov This is already introduced.
You can use client.poll(txHash) to wait for transaction.
The difference is that waitMined function from example additional get the transaction info(contract result data)