> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xyzchain.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Transactions

> Send tokens, execute contracts, and broadcast transactions with the SDK

# Transactions

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

## Creating a Signing Client

<CodeGroup>
  ```typescript Node.js (Mnemonic) theme={null}
  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);
  ```

  ```typescript Browser (Wallet) theme={null}
  import { showWalletModal, createContractClient } from "@xyz-chain/sdk";

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

  // wallet.address and wallet.signer are available for transactions
  ```
</CodeGroup>

## Send Native Tokens

### Send XYZ (Convenience)

```typescript theme={null}
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

```typescript theme={null}
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:

```typescript theme={null}
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

```typescript theme={null}
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

```typescript theme={null}
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

```typescript theme={null}
import { mintCW20 } from "@xyz-chain/sdk";

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

### Burn CW20

```typescript theme={null}
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):

```typescript theme={null}
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

```typescript theme={null}
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:

```typescript theme={null}
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:

```typescript theme={null}
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

<CardGroup cols={2}>
  <Card title="Queries" icon="magnifying-glass" href="/sdk/queries">
    Read balances and contract state
  </Card>

  <Card title="Wallets" icon="wallet" href="/sdk/wallets">
    Connect Keplr, Leap, or XYZ Wallet
  </Card>
</CardGroup>
