Transactions

Learn how to create and broadcast transactions with Stacks.js.

The following shows how to create a simple transaction (STX transfer) using Stacks.js in different environments.

Create a transaction

  import { openSTXTransfer } from '@stacks/connect';
  import { StacksTestnet } from '@stacks/network';
  import { AnchorMode } from '@stacks/transactions';

  openSTXTransfer({
    network: new StacksTestnet(),

    recipient: 'ST39MJ145BR6S8C315AG2BD61SJ16E208P1FDK3AK', // which address you are sending to
    amount: 10000, // tokens, denominated in micro-STX
    anchorMode: AnchorMode.Any,

    onFinish: response => console.log(response.txid),
    onCancel: () => console.log('User canceled'),
  });