Skip to content

Create Stellar payment transaction builder utility #247

@davedumto

Description

@davedumto

Description

Create a utility module for building Stellar payment transactions using @stellar/stellar-sdk. This will be used by the tip modal to construct XLM payment transactions from viewer to creator.


Current State

We have @stellar/stellar-sdk installed (from the Stellar migration), but no payment-specific utilities yet. We need a clean abstraction for building tip transactions.


What needs to happen

  1. Create lib/stellar/payments.ts with the following functions:
import {
  Server,
  TransactionBuilder,
  Networks,
  Operation,
  Asset,
  BASE_FEE,
  Memo,
  Transaction,
} from "@stellar/stellar-sdk";

interface BuildTipTransactionParams {
  sourcePublicKey: string;      // Viewer's Stellar wallet
  destinationPublicKey: string; // Creator's Stellar wallet
  amount: string;               // XLM amount (e.g., "10.0000000")
  network: "testnet" | "mainnet";
}

export async function buildTipTransaction(
  params: BuildTipTransactionParams
): Promise<Transaction>

export async function submitTransaction(
  transaction: Transaction,
  network: "testnet" | "mainnet"
): Promise<{ success: boolean; hash?: string; ledger?: number; error?: string }>
  1. Implementation details:

    • Use Server from @stellar/stellar-sdk to connect to Horizon API
    • Testnet: https://horizon-testnet.stellar.org
    • Mainnet: https://horizon.stellar.org
    • Load source account with server.loadAccount(sourcePublicKey)
    • Build transaction with TransactionBuilder
    • Add Operation.payment() with Asset.native() (XLM)
    • Add memo: Memo.text("StreamFi Tip")
    • Set timeout: 30 seconds
    • Use BASE_FEE for transaction fee
  2. Error handling:

    • Catch and return errors from server.loadAccount() (account not found)
    • Catch and return errors from server.submitTransaction() (insufficient balance, etc.)
    • Include Stellar result codes in error responses
  3. Get network from environment variable:

    • Read NEXT_PUBLIC_STELLAR_NETWORK (set by user: "testnet" or "mainnet")

Files affected

  • New file: lib/stellar/payments.ts

Acceptance criteria

  • lib/stellar/payments.ts file created with both functions
  • buildTipTransaction() constructs valid Stellar payment transaction
  • submitTransaction() submits to Horizon API and returns result
  • Network selection works (testnet vs mainnet based on param)
  • Transactions include memo: "StreamFi Tip"
  • TypeScript types defined for all params and returns
  • Error handling implemented with clear error messages
  • Tested on Stellar Testnet with real wallet addresses

Useful resources


Loom Video Requirement

Before submitting your PR, you must record a short Loom video demonstrating:

  1. The lib/stellar/payments.ts file and its code
  2. Testing buildTipTransaction() with console.log showing the transaction object
  3. Testing submitTransaction() on Testnet and showing the returned hash
  4. Viewing the transaction on Stellar Expert Testnet explorer

Include the Loom link in your PR description.

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programfrontendstellarStellar blockchain integrationtippingCrypto tipping feature using Stellar

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions