Hello,
Does the SDK offer a way to wait for a transaction to be mined and get its status(success/failed)?
Thanks.
Hello,
Does the SDK offer a way to wait for a transaction to be mined and get its status(success/failed)?
Thanks.
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():
try:
tx_hash = "th_XWPEjQfF6PY27V2ruJgDeMkbHTScqyEkgQoPBF2DNSokRSW98"
n = NodeClient(
external_url="https://sdk-mainnet.aepps.com",
key_block_confirmation_num=10 # number of blocks for considering a block mined (default 3)
)
# wait for a transaction to be included and confirmed
n.wait_for_confirmation(tx_hash)
# wait for a transaction to appear in the chain (no confirmations)
n.wait_for_transaction(tx_hash)
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
main()
Hi,
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}`)
resolve()
})
})
})
}
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.
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)