Skip to content
Astrohacker

EarthBucks Swap: Trade EBX for Bitcoin Cash, Wallet to Wallet

EarthBucks Swap is live. You trade EBX for Bitcoin Cash with another person, with a hash time lock contract on each chain. Nobody holds your coins during the trade, and EarthBucks never has your keys.

A single key lies between two open padlocks.

Alice has EBX and wants Bitcoin Cash (BCH). Bob has BCH and wants EBX. They agree on a price. Who sends first?

If Alice sends first, Bob can keep her EBX and send nothing. If Bob sends first, Alice can do the same. The usual answer is an exchange: both people give their coins to a company, and the company does the trade. Then the company holds everybody’s coins. Sometimes it loses them.

Yesterday we launched EarthBucks Swap. It gives a different answer. Alice and Bob trade directly, from wallet to wallet. Either both of them get the agreed coins, or both of them get their own coins back. Nobody holds the coins in the middle, and that includes us.

How a swap works

A swap uses one contract on each chain: a hash time lock contract (HTLC). Each contract locks coins with two ways to spend them:

  • Claim: the other person can take the coins with a secret and their signature.
  • Refund: the owner can take the coins back after a deadline.

Alice’s browser makes a random secret and gives Bob only its SHA-256 hash. Both contracts use that same hash. Then the two wallets do these steps:

  1. Alice locks her EBX. Bob’s wallet waits until the lock is final.
  2. Bob locks his BCH. Alice’s wallet waits for a BCH confirmation.
  3. Alice claims the BCH. Her claim puts the secret on the BCH blockchain.
  4. Bob’s wallet reads the secret from her claim and claims the EBX.

Step 3 is the important one. Alice cannot take the BCH without showing the secret to the world. Bob does not have to trust a message from Alice. His wallet gets the secret from her transaction.

The deadlines do the rest. Bob’s BCH refund opens first, and Alice’s EBX refund opens hours later. Thus Alice cannot take back her EBX and also claim Bob’s BCH. And after Alice shows the secret, Bob has hours to claim the EBX.

Two new things in the EBX script language

EBX and BCH are different blockchains with different rules. Two changes to EBX made the same contract possible on both chains.

SHA-256. EBX uses BLAKE3 for its transaction IDs and signatures. BCH does not have BLAKE3. So we added OP_SHA256 to EBX, and both locks check the same hash. The transaction IDs and signatures of EBX do not change.

The fee is in the script. The taker of a trade pays a 1% fee. That fee is not a separate payment that a wallet can forget. The lock script checks that a claim pays the fee, and a claim without the fee is not valid. A refund needs no fee, so a trade that fails costs no Swap fee. For this check, we added three introspection opcodes to EBX: OP_INPUTINDEX, OP_OUTPUTVALUE and OP_OUTPUTBYTECODE. BCH has had the same opcodes, with the same codes, since 2022.

The EBX lock also keeps the recovery and expiry paths that every EBX output has. A swap lock is not an exception to that rule. Recovery opens after 60 days. A refund opens after a few hours. So recovery cannot touch a live trade.

The successful trade was the easy part

The happy path worked in an offline prototype in September. Most of the work since then was the unhappy paths:

  • A wallet closes in the middle of a trade.
  • A transaction drops out of the mempool.
  • A BCH block comes late, or a reorganization removes one.
  • The network does not answer, so the wallet does not know if its transaction went out.
  • A lock arrives too close to its deadline.

The wallet now handles each of these. It does not start a step that cannot finish in time. It saves each signed transaction before it sends it, and it sends the same transaction again, never a different one. When it sees a secret, it keeps it, because a reorganization can remove a transaction but cannot make a public secret private again. We audited the swap code eight times and fixed what each audit found.

The first trade on the real networks settled on October 18: 1 EBX for 0.00376407 BCH.

What it does not do

An atomic swap is atomic only while your wallet acts before each deadline. This is true of every atomic swap, not only ours. Your keys are in your browser, so your browser does the steps. Keep an EarthBucks tab open until your trade is done. The deadlines give each step a margin of hours, but no margin protects a wallet that stays closed for the full window.

Today, Swap also depends on the earthbucks.com server. The server finds the other person, relays the messages, builds transactions for your wallet to check, and watches both chains. It cannot move your coins: your wallet checks each transaction before it signs, and each lock pays only the other person with the secret or you after the refund. But your wallet trusts the server’s view of each chain. If the server stops, the locks stay on the chains with their refund paths.

The limits are small for the launch:

  • One trade is $1 to $100 of BCH.
  • One account can trade $1,000 in 24 hours.
  • One account can have 5 open cards and trades in progress together.
  • The taker pays 1%. The maker pays no fee. EBX transactions have no network fee, and each BCH transaction of a swap pays 1,000 satoshis.

Every user can trade. Only trades between two verified users count in the EBX price index.

Why this matters for Astrohacker

EBX needs a market. A currency that nobody can buy or sell has no real price. Swap is the first market for EBX where nobody holds the coins. Each price in the index comes from a real trade between two self-custodial wallets.

This is the same idea as the rest of EarthBucks: your keys, your money. We think that agents will soon buy, sell and hire for the people who own them. That economy needs a way to trade value without giving it to a middleman. Swap is a first piece of that. Today, it is a room for people in a browser, not an API for agents.

Next, we will publish open-source wallet node software. Anybody will be able to run a wallet node on their own domain, for EBX, BCH and other UTXO chains. Wallet nodes will connect like email servers, so that alice@earthbucks.com can send a payment, a message or a swap to bob@example.com. That is planned, not shipped. It is part of EarthBucks 2.0.

Read more

Swap launched with four posts on the EarthBucks blog:

Try it

  1. Deposit some BCH on the Bitcoin Cash page of your wallet, or mine some EBX.
  2. Open Swap.
  3. Take a card, or post one with Sell EBX or Buy EBX.
  4. Keep the tab open until your trade settles.

← Back to News