Skip to main content

Transactions

Transactions require a signing client — either from a mnemonic (Node.js) or a wallet connection (browser).

Creating a Signing Client

import { createSigningClient } from "@xyz-chain/sdk";

const client = await createSigningClient(
  { rpcEndpoint: "http://67.205.164.156:26657" },
  "your twelve word mnemonic phrase goes here ..."
);

console.log("Address:", client.address);

Send Native Tokens

Send XYZ (Convenience)

import { sendXYZ } from "@xyz-chain/sdk";

// Send 10 XYZ (amount in uxyz)
const result = await sendXYZ(client, "xyz1...recipient", "10000000");

console.log(result.transactionHash);  // TX hash
console.log(result.code);             // 0 = success
console.log(result.gasUsed);          // Gas consumed

Send Any Token

import { sendTokens } from "@xyz-chain/sdk";

const result = await sendTokens(client, "xyz1...recipient", [
  { denom: "uxyz", amount: "10000000" },
]);

Send Options

Both sendXYZ and sendTokens accept optional parameters:
const result = await sendXYZ(client, "xyz1...recipient", "10000000", {
  memo: "Payment for services",    // Transaction memo
  gas: "200000",                   // Manual gas limit
  gasPrice: "0.025uxyz",           // Gas price
  gasAdjustment: 1.3,             // Multiplier for estimated gas
});

Execute Smart Contracts

Generic Contract Execution

import { createContractClient, executeContract } from "@xyz-chain/sdk";

const config = { rpcEndpoint: "http://67.205.164.156:26657" };
const contractClient = await createContractClient(config, wallet);

const result = await executeContract(
  contractClient,
  wallet.address,
  "xyz1...contract",
  { transfer: { recipient: "xyz1...", amount: "1000000" } },
  {
    memo: "Token transfer",
    funds: [{ denom: "uxyz", amount: "100000" }],  // Optional attached funds
  }
);

console.log(result.transactionHash);
console.log(result.events);  // Contract events emitted

CW20 Token Operations

The SDK provides dedicated helpers for common CW20 operations:

Transfer CW20

import { transferCW20 } from "@xyz-chain/sdk";

const result = await transferCW20(
  contractClient,
  wallet.address,
  "xyz1...token",       // CW20 contract address
  "xyz1...recipient",   // Recipient address
  "1000000"             // Amount in micro-units
);

Mint CW20

import { mintCW20 } from "@xyz-chain/sdk";

const result = await mintCW20(
  contractClient,
  wallet.address,
  "xyz1...token",
  "xyz1...recipient",
  "5000000"
);

Burn CW20

import { burnCW20 } from "@xyz-chain/sdk";

const result = await burnCW20(
  contractClient,
  wallet.address,
  "xyz1...token",
  "1000000"
);

Send CW20 (to a Contract)

Used for launchpad sells and AMM swaps (CW20 Send pattern):
import { sendCW20 } from "@xyz-chain/sdk";

// Sell tokens on launchpad (sends to launchpad contract with encoded message)
const result = await sendCW20(
  contractClient,
  wallet.address,
  "xyz1...token",           // CW20 token contract
  "xyz1...launchpad",       // Recipient contract
  "1000000",                // Amount
  { min_xyz_out: "500000" } // Inner message (auto base64-encoded)
);

Increase CW20 Allowance

import { increaseAllowanceCW20 } from "@xyz-chain/sdk";

const result = await increaseAllowanceCW20(
  contractClient,
  wallet.address,
  "xyz1...token",
  "xyz1...spender",
  "5000000"
);

Transaction Results

All transaction functions return a result with:
interface TxResult {
  transactionHash: string;  // The transaction hash
  code: number;             // 0 = success, non-zero = error
  gasUsed: number;          // Gas consumed
  gasWanted: number;        // Gas limit
}

// Contract executions also include:
interface ExecuteResult extends TxResult {
  events: ContractEvent[];  // Events emitted by the contract
  data?: string;            // Optional return data
}

Fee Configuration

The SDK auto-estimates gas by default. Override for specific use cases:
const result = await executeContract(
  contractClient,
  wallet.address,
  "xyz1...contract",
  { some_action: {} },
  {
    gas: "500000",          // Manual gas limit
    gasPrice: "0.025uxyz",  // Gas price
    gasAdjustment: 1.5,     // Safety multiplier
  }
);

Next Steps