Guides › Test on a chain fork
There is no separate testnet and no faucet. The safe way to experiment is to run a fork of the live chain on your own machine with anvil (Foundry): same contracts, same pools, same balances as mainnet at the block you choose — but every transaction stays on your machine.
Run
anvil --fork-url https://rpc.btcw.tech
anvil serves RPC at http://127.0.0.1:8545, keeps chain ID 482120, and creates 10 test wallets, 10,000 BTCw each (private keys are printed to the console —
local use only, never use them on mainnet). Pin the block so every run is identical:
anvil --fork-url https://rpc.btcw.tech --fork-block-number 124000
Try a swap
ME=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 # anvil test wallet #0
RPC=http://127.0.0.1:8545
cast call 0xd953d53414a81eb6AC5a4edE73d13992181aF51E "quoteSellBtcw(uint256)(uint256)" 1000000000000000 --rpc-url $RPC
cast send 0xd953d53414a81eb6AC5a4edE73d13992181aF51E "sellBtcw(uint256)" 82000000000000000000 \
--value 1000000000000000 --from $ME --unlocked --rpc-url $RPC
cast call 0x3b5BD179CA6Aab4DAF0f842829776843ABe6e727 "balanceOf(address)(uint256)" $ME --rpc-url $RPC
These exact commands were run on 30 Sep 2026: sold 0.001 BTCw, received ~83 USDw. Adjust minUsdOut to the quote you get.
Using the SDK and quote API with a fork
The SDK accepts an optional RPC, so quotes and prebuilt transactions are read from your fork:
import { getQuote } from "./btcw-swap.js"; // copy the file locally, see the SDK page
const q = await getQuote({ from: "native", to: "0x3b5BD179CA6Aab4DAF0f842829776843ABe6e727",
amount: 10n ** 15n, sender: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", rpc: "http://127.0.0.1:8545" });
The btcw.tech/api/v2/swap/quote API always reads mainnet — with a fork, use the SDK as above.
Impersonate any wallet
To test with the token balances of a real wallet (on the fork only):
cast rpc anvil_impersonateAccount 0xWalletToImpersonate --rpc-url $RPC
cast send … --from 0xWalletToImpersonate --unlocked --rpc-url $RPC
Notes
- anvil reads state from
rpc.btcw.techon demand, so it is subject to the 10 requests/second per IP rate limit. If you hit 429 errors with a large test suite, lower--compute-units-per-second(default 330) so anvil throttles itself, e.g.--compute-units-per-second 150. - The oracle does not update on a fork: 300 seconds after the fork block, OracleAMM reports
StalePrice. Restart anvil to fork from the latest block. - The bridge does not work on a fork — there is no relayer. You can test
approve+transferRemote, but not delivery. - Foundry tests:
forge test --fork-url https://rpc.btcw.techruns Solidity tests against live state.