Comment on page

Submitting a Transaction

Submitting a transfer via the api is a simple process
import { WsProvider, ApiPromise } from "@polkadot/api"
const BOB = '2xBchgbq7aQyGjTotgQvP9Uh76uEWfQWYBpAzJgn5dfsfhsW'
const MNEMONIC = "outer exit wish coconut category liberty fade diagram logic noodle frozen safe"
async function main () {
// Instantiate the API
const WATR_ENDPOINT = "wss://"
const provider: WsProvider = new WsProvider(WATR_ENDPOINT)
const api = await ApiPromise.create({ provider })
// Construct the keyring after the API (crypto has an async init)
const keyring = new Keyring({ type: 'sr25519' })
// Add account
const account = keyring.addFromMnemonic(MNEMONIC)
// Create a extrinsic, transferring 12345 units to Bob
const transfer = api.tx.balances.transfer(BOB, 12345);
// Sign and send the transaction using our account
const hash = await transfer.signAndSend(account);
console.log('Transfer sent with hash', hash.toHex());