Skip to main content

Overview

Sending assets uses the standard wallet.send() method. Specify the recipient address, an optional BTC amount (in satoshis), and the assets to transfer. The recipient does not need to be online.

Setup

Import the SDK and create a wallet:
import { MnemonicIdentity, Wallet } from '@arkade-os/sdk'

const identity = MnemonicIdentity.fromMnemonic("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon")

const wallet = await Wallet.create({
  identity,
  arkServerUrl: 'https://arkade.computer',
})
Your wallet needs an offchain balance to cover transaction fees. See Receiving Payments to fund your wallet.

Receive Assets

You can either receive assets directly to your Arkade address, or issue a new asset:
const { assetId } = await wallet.assetManager.issue({
  amount: 10101, // [101.01]
  metadata: {
    name: 'ABC Token',
    ticker: 'ABC',
    decimals: 2,
    icon: 'https://example.com/abc.png',
  },
})

Send a Partial Amount

Transfer some units of an asset to another wallet. The remaining units stay in your wallet as change.
const { txid } = await wallet.send({
  address: recipientAddress,
  assets: [{ assetId, amount: 543 }], // [5.43]
})

Send All Units

First, calculate your remaining balance:
const vtxos = await wallet.getVtxos()
const assetPackets = vtxos
  .flatMap((v) => v.assets ?? [])
  .filter((a) => a.assetId === assetId)
const assetBalance = assetPackets.reduce((sum, a) => sum + a.amount, 0)
console.log(assetBalance) // 9558 [95.58]
Now, transfer the entire asset balance to another wallet:
const { txid } = await wallet.send({
  address: recipientAddress,
  assets: [{ assetId: myAssetId, amount: assetBalance }],
})
After sending all units, your wallet will have zero balance for that asset.

Send with BTC

Attach a BTC amount alongside the asset transfer:
const { txid } = await wallet.send({
  address: recipientAddress,
  amount: 5000, // 5000 sats
  assets: [{ assetId, amount: 200 }], // [2.00]
})
The recipient receives both the BTC and the asset on the same VTXO.

Send Multiple Assets

Pass multiple entries in the assets array to send several assets in one transaction:
const { assetId: tokenA } = await wallet.assetManager.issue({
  amount: 100
})
const { assetId: tokenB } = await wallet.assetManager.issue({
  amount: 500
})

const { txid } = await wallet.send({
  address: recipientAddress,
  assets: [
    { assetId: tokenA, amount: 75 },
    { assetId: tokenB, amount: 250 },
  ],
})

Next Steps