Book a free call

How to Implement a Cross-Chain Bridge Step by Step

A cross-chain bridge moves tokens between chains by locking on one side and releasing on the other. Here is how to build one safely, step by step.

Hertiv engineering teamReviewed by a senior engineer
7 min read
How to Implement a Cross-Chain Bridge Step by Step
On this page

Short answer

A cross-chain bridge is software that moves tokens or messages between two blockchains by locking assets on the source chain and releasing matching assets on the destination chain. Implementing one means building the bridge contracts, a way to verify events across chains, and the monitoring that catches a bad transfer before it settles.

What is a cross-chain bridge?

A cross-chain bridge is software that lets value or messages move from one blockchain to another. It locks tokens on the source chain, checks that the lock happened, and then releases or mints matching tokens on the destination chain.

Bridges exist because blockchains do not read each other. A token on one chain cannot simply appear on another, so the bridge holds the original and issues a representation of it. The user ends up with a token they can spend on the destination chain, while the original stays locked in the bridge contract.

Implementing a bridge is not the same as using one. A user only needs a wallet and a bridge interface. A builder must write the contracts that hold funds, choose how events are verified, run the off-chain software that watches both chains, and plan for what happens when something goes wrong. For teams building cross-chain products, blockchain development covers the wider design choices.

Which bridge design should you choose?

The bridge design you choose decides what can go wrong and how much you must trust the operators. Pick the design before writing any contract code, because it shapes everything else.

DesignHow it moves valueTrust neededBest for
Lock and mintLocks tokens, mints wrapped tokensValidators or custodiansCommon token transfers
Burn and mintBurns on one side, mints on the otherValidators or custodiansTokens you control
Liquidity poolsSwaps through pools on both sidesPool operatorsFast transfers
Atomic swapsTwo parties swap with time locksAlmost nonePeer-to-peer trades

Lock and mint is the most common choice for a first bridge, because the pattern is well understood and the contracts are simple to reason about. Liquidity pools move faster but need capital on both chains. Atomic swaps need the least trust, but they only work when two parties want the opposite trade at the same time.

A light client design, where one chain checks the other chain's proofs directly, needs the least trust of all, but it is also the hardest to build. Most teams start with a validator set and add stronger verification later, once the bridge has real volume.

How do you build the bridge contracts?

You build the bridge contracts as two small programs, one on each chain, plus a clear rule for who may call them. Keep the contracts small, because every line of bridge code guards other people's funds.

  1. Write the lock contract. On the source chain, a contract that accepts deposits, records the amount and the destination address, and emits an event. Nothing else.
  2. Write the release contract. On the destination chain, a contract that mints or releases tokens only when it receives a signed instruction from the verifier set.
  3. Set the verifier rules. Decide how many signatures are needed, who holds the keys, and how keys are replaced. Put limits on how much can move in one transfer and in one day.
  4. Add a pause switch. Give a named role the power to halt deposits and releases. A pause that nobody can trigger is a bridge with no emergency brake.
  5. Test on testnets first. Run the full flow on both testnets, including failed transfers, reverted transactions and a verifier going offline.
  6. Get an audit. Have the contracts reviewed by an independent auditor before mainnet, and fix every finding the auditor marks as high severity.

Contracts that hold funds should do as little as possible. Logic that can live off-chain, such as fee calculation or routing, should live off-chain. The contracts should only lock, release and enforce limits. Smart contract development follows the same rule: small contracts are easier to audit and harder to break.

How do relayers and validators move messages?

Relayers and validators are the off-chain part of the bridge. They watch the source chain, confirm that a deposit happened, and tell the destination chain to release the matching tokens.

A relayer is a server that reads events from the source chain and submits a signed message to the destination chain. A validator set is a group of independent parties that each sign the message, and the release contract only acts when enough signatures are present. The number of signatures needed is the bridge's security threshold.

Run more than one relayer, on separate machines and ideally in separate regions. If a single relayer goes down, deposits pile up and users wait. If a single relayer is compromised, it can submit false messages, so the release contract must require signatures from a quorum of validators, not from one relayer alone.

Keep a log of every message, signature and release, with timestamps. When a transfer fails or a user reports a missing payment, that log is how you find out what happened. A bridge without clear logs is a bridge you cannot support.

Example: a team bridges a stablecoin between two chains

Example (hypothetical): a small team wants to let users move a stablecoin between chain A and chain B. They choose a lock-and-mint design with five validators, of which three must sign each release.

On chain A they deploy a lock contract. A user deposits 1,000 stablecoins, and the contract emits an event with the amount and the user's address on chain B. Three of the five validators see the event, check it against their own copy of chain A, and sign a release message. A relayer submits the three signatures to the release contract on chain B, which mints 1,000 wrapped stablecoins to the user.

The team sets a per-transfer limit of 50,000 and a daily limit of 200,000. In the first week the bridge moves 60,000 a day across 40 transfers, so the daily limit never binds. One validator goes offline for a day, and the bridge keeps working because three of the remaining four can still sign. The team also runs a monitor that alerts them if a release is requested without a matching deposit.

The example shows why the limits matter. If an attacker had stolen two validator keys, they could sign a release for 50,000 at most, and the daily limit would stop a second large transfer. The team would have time to pause the bridge and rotate the keys.

How do you test a bridge before launch?

You test a bridge by trying to break it on testnets before real funds are at risk. A bridge that only passes its happy-path test is not ready for mainnet.

Start with the normal flow on both testnets: deposit, sign, release, and the reverse trip back. Then test the failures: a deposit that reverts, a relayer that stops, a validator that signs a wrong amount, and a user who sends to an address that cannot receive the token. Each failure should leave funds safe and produce a clear log entry.

Run a test where the destination chain reorganises and the release transaction is dropped, then resubmitted. Run a test where the bridge is paused mid-transfer and resumed. Run a load test with many small transfers in a short window, to see whether the relayer keeps up and whether fees stay sane.

Before launch, have the contracts audited and run a public testnet for a few weeks with real users moving test tokens. The bugs that appear in that window are far cheaper than the same bugs on mainnet. Smart contract audit is the last gate, not the first test.

What are the common mistakes?

The most common bridge mistakes are trusting a single relayer, skipping limits, and treating the audit as the only test. Each of these has cost real bridges real money.

  • One relayer, one key. A single point of failure that can halt the bridge or submit false messages. Use a quorum of validators and more than one relayer.
  • No transfer limits. Without per-transfer and daily limits, a single bad signature can drain the whole bridge. Limits buy time to pause and respond.
  • No pause switch. A bridge that cannot be halted cannot be saved when an attack is spotted. Add a pause, and test that it works.
  • Skipping the failure tests. Testing only the happy path leaves reorgs, dropped transactions and offline validators untested until they happen live.
  • Logging nothing. Without logs of deposits, signatures and releases, you cannot answer a user who says their funds never arrived.
  • Launching with unaudited contracts. An audit is not a guarantee, but skipping it removes the one independent check on code that guards other people's funds.

Key takeaways

  • A bridge locks assets on one chain and releases matching assets on the other
  • Choose the design first: lock and mint is the simplest start, light clients need the least trust
  • Keep bridge contracts small, with limits, a pause switch and a validator quorum
  • Run more than one relayer and log every deposit, signature and release
  • Test failures on testnets, then audit, before any real funds move

Frequently asked questions

What is the difference between a bridge and a swap?

A bridge moves the same asset between chains, usually by locking it on one side and minting a wrapped version on the other. A swap exchanges one asset for a different one, often on the same chain. Some bridges include a swap step, but the bridge part is the cross-chain movement itself.

How long does a bridge transfer take?

It depends on the design and the chains involved. A transfer needs the source transaction to confirm, validators to sign, and the destination transaction to confirm. That can take minutes on fast chains and longer when a chain needs many confirmations before the deposit is treated as final.

Do I need my own token to run a bridge?

No. A lock-and-mint bridge can move an existing token by issuing a wrapped version on the destination chain. A burn-and-mint design needs control of the token supply, so it only works for tokens your team issues or has an agreement to mint.

What happens if a relayer goes offline?

Deposits keep arriving but releases stop until another relayer picks the messages up. That is why bridges run more than one relayer. A quorum of validators can still sign, so the bridge recovers as soon as a working relayer submits the signed messages.

How much should a bridge transfer cost?

The cost is the source chain fee plus the destination chain fee plus any bridge fee. Fees vary by chain and by how busy the network is, so check the bridge interface before sending. See the bridge operator's fee page for current figures.

Can a bridge be fully trustless?

A light client bridge, where one chain verifies the other chain's proofs directly, comes closest. Most bridges in use today rely on a validator set, which means users trust that a quorum of validators will act honestly. Stronger verification is possible but harder to build.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: blockchain systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Planning a cross-chain product? Talk to Hertiv.

A senior engineer replies within one business day. Or see our Smart Contract Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call