Transactions

Transaction apis are designed to be compatible with IKeyringPair and Signer interfaces, so you can sign the transactions with accounts created by a Keyring or from any Polkadot{.js}-based wallet extensions.

All transaction apis are exposed in ChainApi interface and can be access with syntax: client.tx.<pallet>.<transactionName>. E.g: Available transaction apis for Polkadot network are defined here, similarly for other networks as well.

Sign & send a transaction

Example 1: Sign transaction with a Keying account

import { cryptoWaitReady } from '@polkadot/util-crypto';
import { Keyring } from '@polkadot/keyring';

// ...

await cryptoWaitReady();
const keyring = new Keyring({ type: 'sr25519' });
const alice = keyring.addFromUri('//Alice');

const { status } = await client.tx.balances
    .transferKeepAlive(<destAddress>, 2_000_000_000_000n)
    .signAndSend(alice, ({ status }) => {
        console.log('Transaction status', status.type);
    })
    .untilFinalized();
  
console.log(`Transaction finalized at block hash ${status.value.blockHash}`);

Example 2: Sign transaction using Signer from Polkadot{.js} wallet extension

Example 3: Submit a batch transaction
Example 4: Teleport WND from Westend Asset Hub to Westend via XCM

SubmittableExtrinsic

SubmittableExtrinsic is an extrinsic instance that's ready to sign and send to the network for inclusion. A SubmittableExtrinsic will be created after you execute a tx method with required arguments.

sign

Sign the extrinsic using the IKeyringPair or Signer

You can also customize the transaction by using signer options as the second parameter:

send

Send the extrinsic to the network

And watch its status as needed

signAndSend

Sign and send the extrinsic to the network. This method's simply a combination of sign & send methods.

Or pass in an options object to customize the transaction parameters

paymentInfo

Estimate gas fee for a transaction

Tx Resolver Methods

untilBestChainBlockIncluded

Wait until the transaction is included in best chain block and resolve to return the result (SubmittableResult) with access to on-chain events, status, and dispatchInfo ...

untilFinalized

Similarly, wait until the transaction is included in a finalized block and resolve.

SubmittableResult

TODO

TxStatus

Available statuses of a transaction:

SignerOptions

Last updated

Was this helpful?