Skip to main content

Sign Transaction

To sign a transaction use the adapter object created in the connect step.

Before you sign the transaction, you have to create it using the ApiPromise class from the @polkadot/api package, like so.

import { ApiPromise, WsProvider } from "@polkadot/api";

let api: ApiPromise | undefined;
// use any polkadot, aleph zero or vara rpc
const provider = new WsProvider("wss://ws.test.azero.dev/");

ApiPromise.create({
provider,
}).then((api) => {
api = api;
});

Finally you can sign and send the transaction.

import { Signer } from "@polkadot/api/types";

// Create transaction
const payload = api.tx.balances.transfer(RECEIVER_PUBLIC_KEY, 50000);
// Sign transaction using adapter
const signed = await payload.signAsync(SENDER_PUBLIC_KEY, { signer: adapter.signer as Signer});
// Send transaction
await signed.send();