Local Transaction API

The Local Transaction API provides maximum security and control. We build the transaction for you, but you sign and broadcast it using your own wallet and RPC endpoint.

Overview

Base URL: https://api.turnpike.dev

Flow:

  1. Request a transaction from Turnpike

  2. Receive base64-encoded unsigned transaction

  3. Sign the transaction with your wallet

  4. Broadcast to Solana using your RPC endpoint

Why Use Local Transactions?

  • Full Control: You sign and send transactions yourself

  • Custom RPC: Use your own Solana RPC infrastructure

  • Maximum Security: Private keys never leave your system

  • Transaction Transparency: Inspect transactions before signing

  • Institutional Grade: Meets compliance requirements

Endpoints

Build Buy Transaction

Build an unsigned transaction for buying tokens.

Endpoint: POST /transaction/buy

Request Body:

Parameter
Type
Required
Description

publicKey

string

Yes

Your Solana wallet public key

mint

string

Yes

Token mint address to purchase

amount

number

Yes

Amount of SOL to spend

slippage

number

No

Maximum slippage percentage (default: 10)

priorityFee

number

No

Priority fee in SOL (default: auto)

Example Request:

Success Response (200):


Build Sell Transaction

Build an unsigned transaction for selling tokens.

Endpoint: POST /transaction/sell

Request Body:

Parameter
Type
Required
Description

publicKey

string

Yes

Your Solana wallet public key

mint

string

Yes

Token mint address to sell

amount

number

Yes

Amount of tokens to sell

slippage

number

No

Maximum slippage percentage

priorityFee

number

No

Priority fee in SOL

Example Request:

Success Response (200):

Signing and Sending

After receiving the unsigned transaction, you need to sign and broadcast it.

JavaScript/TypeScript Example

Using with Wallet Adapter (Browser)

Python Example

Rust Example

Transaction Expiration

Transactions have a limited validity period:

  • lastValidBlockHeight: Block height after which transaction is invalid

  • expiresAt: Unix timestamp when transaction expires (typically 60 seconds)

Always send transactions promptly after building them.

Best Practices

  1. Verify Transaction Contents: Inspect the transaction before signing

  2. Use Trusted RPC: Use your own RPC or a trusted provider

  3. Handle Expiration: Build and send transactions quickly

  4. Confirm Transactions: Always wait for confirmation

  5. Store Private Keys Securely: Never expose private keys

  6. Test Thoroughly: Test with small amounts first

Security Considerations

Inspect Before Signing

Simulate Before Sending

Error Handling

Same error codes as Lightning API apply. See Error Handling.

Next Steps

Last updated