How to Sign a Crypto Transaction Offline and Broadcast It

How to Sign a Crypto Transaction Offline and Broadcast It

TL;DR: To send crypto without handing your keys to anyone, split the job in three. Ask the Crypto APIs Blockchain API to prepare an unsigned transaction, with the fee, nonce or inputs worked out. Sign it on your own server with @cryptoapis-io/offline-signer, an MIT-licensed package that makes no network call. Then post the signed hex to one broadcast endpoint and get the transaction ID back. Only the middle step touches a key, and it runs in your process.

Most teams that move funds hit the same wall. Running a node per chain to build and push transactions is a lot of work. Handing a provider your private key to do it for you is worse, because a provider that can sign for you can also move your money. There's a third way, and it's simple: let the API do the chain-specific busywork, and keep signing where your keys already live.

What does "sign offline and broadcast" mean?

A blockchain transaction goes through three stages. First it's built: sender, recipient, amount, plus the details each chain needs, like a nonce and gas fields on Ethereum or the inputs to spend on Bitcoin. Then it's signed with the private key. Then it's broadcast to the network.

Only signing needs the key. Building and broadcasting work with public data. So you can hand those two to an API and keep the signature in-house. That's what we mean by self-custody: you hold the keys, we prepare and broadcast.

Step 1: how do you prepare an unsigned transaction?

You send a sender, a recipient and an amount. Prepare Transactions returns the unsigned transaction with the fee, nonce or inputs filled in, so you don't have to run a node to pick them. Here's a native coin transfer on Ethereum, using Prepare Transaction From Address EVM:

curl -X POST https://rest.cryptoapis.io/prepare-transactions/evm/ethereum/mainnet/native-coins \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_API_KEY" \
  -d '{
    "data": {
      "item": {
        "amount": "2000000009340",
        "nonce": "0",
        "recipient": "0x0902...abc6",
        "sender": "0x1d10...e26b"
      }
    }
  }'

The response carries the fee fields (gasPrice, maxFeePerGas, maxPriorityFeePerGas), the nonce, the recipient and the inputData. Nothing is signed yet, and nothing has left your control.

The same pattern covers coins on EVM, UTXO, XRP, Solana, Tezos and Kaspa chains. For tokens and NFTs you'd use the matching endpoint: ERC-20 and NFT transfers on EVM chains and Tron, TRC-20 on Tron, SPL tokens on Solana, and FA1.2 and FA2 tokens on Tezos. On Bitcoin the request takes a fromAddress and feeOptions with a priority, and you get back the fee and the transaction size. If your addresses come from an xPub, there are endpoints that prepare straight from an address in your synced HD wallet.

Step 2: how do you sign it offline?

Install the signer and import only the chain family you need. There's no client to configure and no API key to pass, because the package never talks to our servers.

npm i @cryptoapis-io/offline-signer
import { evmSignFromDetails } from "@cryptoapis-io/offline-signer/evm";

// item = data.item from the prepare call
const { signedTransactionHex } = await evmSignFromDetails({
  blockchain: "ethereum",
  network: "mainnet",
  privateKey: process.env.PRIVATE_KEY, // never leaves this process
  toAddress: item.recipient,
  value: item.value,
  nonce: item.nonce,
  gasLimit: item.gasLimit,
});

The Offline Signer has six families, each behind its own import path: /evm (Ethereum, BNB Smart Chain, Polygon, Avalanche, Arbitrum, Base, Optimism and more), /utxo (Bitcoin, Bitcoin Cash, Litecoin, Dogecoin, Dash, Zcash), /tron, /xrp, /kaspa and /solana. Signing EVM never pulls in the Bitcoin or Solana stacks. And it's MIT, so if you ever stop using our API, your signing code keeps working.

Step 3: how do you broadcast a signed transaction?

One endpoint, one field. Broadcast Locally Signed Transaction takes the blockchain and network in the path and your signedTransactionHex in the body:

curl -X POST https://rest.cryptoapis.io/broadcast-transactions/ethereum/mainnet \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_API_KEY" \
  -d '{
    "data": {
      "item": {
        "signedTransactionHex": "0xf86a...",
        "callbackUrl": "https://example.com/hooks/tx",
        "callbackSecretKey": "yourSecretString"
      }
    }
  }'

You get a transactionId back. The callback fields are optional: add an HTTPS URL and a secret, and we'll call your URL with a success or failure status for that transaction. Broadcast Transactions works on Bitcoin, Ethereum, XRP Ledger, Solana, Tron, Tezos, BNB Smart Chain, Polygon, Base and more, on mainnets and on test networks like Sepolia, Amoy, Fuji and Nile.

Where does this fit in a payout or sweep flow?

  1. Your system decides to pay out, or a Blockchain Events webhook tells you a deposit confirmed and should be swept to treasury.
  2. Check the fee level with the Blockchain Fees recommendations if you want to choose your own priority.
  3. Prepare the unsigned transaction.
  4. Sign it in the service that holds the key, ideally an isolated one with no inbound traffic.
  5. Broadcast it and store the transactionId.
  6. Credit or close the payout when your webhook or callback reports the result.

Every step is an ordinary API call you can log and audit. The key is used in exactly one place.

What to watch for

  • Nonces on EVM chains. If you prepare two transfers from one address at the same time, they'll fight over the nonce. Send them in sequence, or set the nonce yourself in the request.
  • Prepare close to signing. Fees move. A transaction prepared an hour ago may underpay. Prepare, sign and broadcast in one short run.
  • Simulate the risky ones. On Ethereum mainnet and Sepolia you can run a transaction through the Transaction Simulator first and see whether it succeeds or reverts, and the gas it uses, without paying a network fee.
  • Treat the callback as a signal, not proof. Verify the callback with your secret key, then confirm the transaction on-chain before you mark a payout final.

FAQ

Can I broadcast a transaction I signed myself?

Yes. Post the signed transaction hex to the Broadcast Locally Signed Transaction endpoint with the blockchain and network in the path. You get the transaction ID back, and an optional callback reports the result.

Does Crypto APIs ever see my private key?

No. Preparing and broadcasting use only public data. Signing happens in your own process with the offline signer, which makes no API call and needs no API key.

Which blockchains can I prepare and sign for?

Prepare Transactions covers EVM, UTXO, XRP, Solana, Tezos and Kaspa chains, plus tokens on EVM chains, Tron, Solana and Tezos. The offline signer signs EVM, UTXO, Tron, XRP, Kaspa and Solana transactions.

Do I need to run my own node?

No. The API works out the fee, nonce or inputs when it prepares the transaction, and relays your signed transaction to the network when you broadcast it.

Start building

Prepare, sign, broadcast: that's the whole loop, and your keys stay home for all of it. It's part of the Crypto APIs Blockchain API. Open the prepare endpoints on our developer portal and send your first unsigned transaction. Already deriving deposit addresses from an xPub? Our post on HD wallet derivation at scale covers the other half of the flow.

Share X f in

Build it on Crypto APIs

14-day free trial, mainnet included. No card needed.