Skip to main content
@chipi-stack/core is in development (v0.1.0). APIs may change before stable release.

Overview

TxBuilder provides a fluent API for composing multiple StarkNet calls into a single atomic transaction. All calls execute together via Account.execute(), which is more gas-efficient than separate transactions (important when sponsoring gas via a paymaster).

Usage

Constructor

Parameters

  • account (Account): A starknet.js Account instance
  • opts.paymaster (PaymasterAdapter, optional): Adapter for gasless transactions via sendSponsored()

Methods

add(call)

Add one or more raw StarkNet calls to the batch.

Parameters

  • call (Call | Call[]): A single Call or array of Calls

Returns

this (chainable)

approve(token, spender, amount)

Add an ERC20 approve call. Handles uint256 encoding automatically.

Parameters

  • token (string): Token contract address
  • spender (string): Address to approve
  • amount (bigint): Raw amount in base units

Returns

this (chainable)

transfer(token, targets)

Add one or more ERC20 transfer calls.

Parameters

  • token (string): Token contract address
  • targets (TransferTarget[]): Array of { to: string, amount: bigint } pairs

Returns

this (chainable)

calls()

Returns a copy of the current call batch (for inspection).

Returns

Call[]

send()

Execute all batched calls atomically.

Returns

Promise<InvokeFunctionResponse>

Throws

  • If no calls have been added
  • If send() was already called (builders are single-use)

sendSponsored()

Execute via Chipi’s paymaster (gasless). Requires a PaymasterAdapter in the constructor.

Returns

Promise<string> (transaction hash)

Throws

  • If no paymaster was configured in the constructor
  • If no calls have been added
  • If send() or sendSponsored() was already called (builders are single-use)

estimateFee()

Estimate the fee for the current batch without executing.

Returns

Promise<EstimateFeeResponse>

Throws

  • If no calls have been added

preflight()

Simulate the transaction without submitting. Returns the transaction trace and fee estimation. Useful for checking if a transaction would succeed before sending.

Returns

Promise<PreflightResult> with transaction_trace and fee_estimation

Throws

  • If no calls have been added

Examples

Simple Transfer

Approve + Swap (Atomic Batch)

Fee Preview Before Sending

With Erc20 and Amount

Gasless with Argent X / Braavos (browser)

Gasless with Cartridge Controller

Backend Automation (gasless)

  • Amount: Type-safe token amounts for use with TxBuilder
  • Erc20: Generate typed Call objects for approve/transfer
  • SignerAdapter: Different signing strategies for the Account