Skip to content

Send Transactions with SDKs

Introduction

Sending transactions on Polkadot SDK-based blockchains involves constructing an extrinsic (transaction), signing it with your account's private key, and submitting it to the network.

This guide uses Subxt, Parity's Rust library for Polkadot SDK-based chains, to send a balance transfer on a local development node. The example signs with the //Alice development account and sends funds to //Bob, so you do not need to fund an account first.

The same transaction flow works with third-party client libraries, for example Polkadot API (PAPI), Dedot, Polkadot.js API, and Python Substrate Interface.

Prerequisites

  • Rust toolchain (latest stable) and Cargo.
  • A local development node listening on ws://127.0.0.1:9944, for example the parachain template node described in Run the Node Locally. The template's development preset funds the well-known development accounts, such as Alice and Bob, as defined in its genesis config presets.

Set Up the Project

  1. Create a new Rust project:

    cargo new subxt-send-tx-example && cd subxt-send-tx-example
    
  2. Install the Subxt CLI:

    cargo install subxt-cli@0.50.1
    
  3. Download the metadata from your local node:

    subxt metadata --url ws://127.0.0.1:9944 -o metadata.scale
    
  4. Update Cargo.toml with the required dependencies:

    Cargo.toml
    [package]
    name = "subxt-send-tx-example"
    version = "0.1.0"
    edition = "2021"
    
    [[bin]]
    name = "send_transfer"
    path = "src/bin/send_transfer.rs"
    
    [dependencies]
    subxt = { version = "0.50.1", features = ["native"] }
    subxt-signer = "0.50.1"
    tokio = { version = "1", features = ["rt", "macros"] }
    

Send a Balance Transfer

The following example constructs, signs, and submits a Balances.transfer_keep_alive transaction, then waits for it to be finalized.

Create a file at src/bin/send_transfer.rs and add the following code to it:

src/bin/send_transfer.rs
use subxt::utils::AccountId32;
use subxt::{OnlineClient, PolkadotConfig};
use subxt_signer::sr25519::dev;

// Generate an interface from the node's metadata
#[subxt::subxt(runtime_metadata_path = "metadata.scale")]
pub mod runtime {}

// WebSocket endpoint of your local development node
const NODE_URL: &str = "ws://127.0.0.1:9944";

// Amount to transfer, in the chain's smallest unit
const AMOUNT: u128 = 1_000_000_000_000;

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize the Subxt client
    let api = OnlineClient::<PolkadotConfig>::from_url(NODE_URL).await?;

    // Anchor to the current block
    let at_block = api.at_current_block().await?;

    println!("Connected to {}", NODE_URL);

    // Use the Alice and Bob development accounts
    let sender_keypair = dev::alice();
    let sender_address = AccountId32::from(sender_keypair.public_key());
    let dest = AccountId32::from(dev::bob().public_key());

    println!("Sender address: {}", sender_address);
    println!("Recipient address: {}", dest);
    println!("Amount: {}\n", AMOUNT);

    // Get sender's account info to check balance
    let account_storage = at_block
        .storage()
        .entry(runtime::storage().system().account())?;
    let account_info = account_storage
        .fetch((sender_address,))
        .await?
        .decode()?;

    println!("Sender balance: {}", account_info.data.free);

    // Build the balance transfer extrinsic
    let balance_transfer_tx = runtime::transactions()
        .balances()
        .transfer_keep_alive(dest.into(), AMOUNT);

    // Sign and submit the extrinsic, then wait for it to be finalized
    println!("\nSigning and submitting transaction...");
    let events = at_block
        .transactions()
        .sign_and_submit_then_watch_default(&balance_transfer_tx, &sender_keypair)
        .await?
        .wait_for_finalized_success()
        .await?;

    // Check for a successful transfer event
    if let Some(event) = events.find_first::<runtime::balances::events::Transfer>() {
        println!("\nTransaction successful!");
        println!("Transfer event: {:?}", event);
    }

    Ok(())
}

Key aspects of the code:

  • Development signer: subxt_signer::sr25519::dev::alice() returns the //Alice development keypair. To sign with your own account on another chain, load it with Keypair::from_phrase instead. For all the ways to create a signer, see Sign Transactions with subxt-signer.
  • Transaction payload: runtime::transactions().balances().transfer_keep_alive() builds a type-checked call from the generated interface.
  • Submission: sign_and_submit_then_watch_default signs the transaction with default parameters, submits it, and returns a progress handle. wait_for_finalized_success waits for finalization and returns the transaction's events.

Warning

Development accounts use publicly known keys. Use them only on local development chains. Never share your mnemonic phrase or private keys, and use secure key management in production.

Run the script:

cargo run --bin send_transfer

The script prints the sender and recipient addresses, the sender's free balance, and the Balances.Transfer event once the transaction is finalized.

Where to Go Next

  • Guide Query On-Chain State


    Learn how to query storage and runtime data with Subxt.

    Get Started

  • Guide Calculate Transaction Fees


    Estimate fees before sending transactions.

    Get Started

Last update: November 17, 2026
| Created: November 17, 2026