1

I am using subxt library . I have downloaded metadata from chain using this url wss://rpc.polkadot.io:443 . I have also implemented default example from subxt documentation of transfer balance . i want to know how can i transfer balance from account a to account b present in my wallet using subxt library

2 Answers 2

3

The account you want to send the funds to (you need the address):

    let account_B: AccountId32 = the_address.parse().unwrap();

The account you want to send the funds from (you need the seed):

let pair = sp_core::sr25519::Pair::from_string(&mnemonic_phrase_A, None).unwrap();
let account_A = PairSigner::new(pair);

Then is the same code as the example

let balance_transfer_tx = polkadot::tx().balances().transfer(account_B, 10_000);

    let events = api
        .tx()
        .sign_and_submit_then_watch_default(&balance_transfer_tx, &account_A)
        .await?
        .wait_for_finalized_success()
        .await?;
1

Base on that example.

Replace the dest with:

array_bytes::hex2array::<_, 32>(your `b` account's public key here).unwrap().into()

And replace the from with:

use sp_core::{sr25519::Pair, Pair as _};
use subxt::tx::PairSigner;

PairSigner::new(Pair::from_seed(&array_bytes::hex2array(your a account's secret seed here).unwrap()))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.