Skip to main content

Documentation Index

Fetch the complete documentation index at: https://yieldxyz.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Overview

Solana transactions returned by the Yield.xyz API can be signed using the official Solana SDK or the Anchor framework. Below you’ll find examples for both approaches.

@solana/web3.js

@solana/web3.js is the official JavaScript SDK for interacting with the Solana blockchain.

Installation

npm install @solana/web3.js bs58

Signing a Transaction

import {
  Connection,
  Keypair,
  Transaction,
  sendAndConfirmTransaction,
} from "@solana/web3.js";
import bs58 from "bs58";

const connection = new Connection(process.env.SOLANA_RPC_URL!, "confirmed");
const keypair = Keypair.fromSecretKey(bs58.decode(process.env.SOLANA_PRIVATE_KEY!));

async function signAndSend(serializedTx: string) {
  const txBuffer = Buffer.from(serializedTx, "base64");
  const transaction = Transaction.from(txBuffer);

  transaction.sign(keypair);

  const signature = await sendAndConfirmTransaction(connection, transaction, [
    keypair,
  ]);

  console.log("Transaction signature:", signature);
  return signature;
}
Use "confirmed" commitment for a good balance between speed and reliability. Switch to "finalized" when you need maximum certainty.