Fetching wBTC, Factory, and Router Addresses on OP_NET

This guide walks you through how to retrieve the wBTC, Factory, and Router addresses, which are essential for interacting with the OP_NET metaprotocol. These addresses are used for token swaps, liquidity pool interactions, and wrapping/unwrapping BTC.


Step 1: Install Required Packages

Ensure that you have the required dependencies installed:

npm install @btc-vision/transaction bitcoinjs-lib

Step 2: Fetch the wBTC Address

The wBTC address represents the Wrapped Bitcoin contract on the OP_NET metaprotocol. You can fetch the wBTC address using the wBTC class provided by the @btc-vision/transaction package.

import { wBTC } from "@btc-vision/transaction";
import * as bitcoinjs from "bitcoinjs-lib";

// Example: Fetch the wBTC address
const network = bitcoinjs.networks.regtest; // Use regtest, testnet, or mainnet

const wbtcAddress = new wBTC(network).getAddress(); // Fetch the wBTC address for the given network

console.log("wBTC Address:", wbtcAddress);

Step 3: Fetch the Factory and Router Addresses

The Factory and Router addresses are used for interacting with decentralized exchanges (DEXes) and liquidity pools. You can directly import the constants for these addresses depending on the network (Regtest, Fractal Testnet).

import {
  FACTORY_ADDRESS_FRACTAL,
  FACTORY_ADDRESS_REGTEST,
  ROUTER_ADDRESS_FRACTAL,
  ROUTER_ADDRESS_REGTEST,
} from "@btc-vision/transaction";

// Example: Fetch Factory and Router addresses for different networks
const factoryAddressRegtest = FACTORY_ADDRESS_REGTEST;
const factoryAddressFractal = FACTORY_ADDRESS_FRACTAL;

const routerAddressRegtest = ROUTER_ADDRESS_REGTEST;
const routerAddressFractal = ROUTER_ADDRESS_FRACTAL;

console.log("Factory Address (Regtest):", factoryAddressRegtest);
console.log("Factory Address (Fractal):", factoryAddressFractal);
console.log("Router Address (Regtest):", routerAddressRegtest);
console.log("Router Address (Fractal):", routerAddressFractal);

Step 4: Example Output

When running this code, you'll see the addresses for wBTC, Factory, and Router for the respective networks. Example output on Regtest might look like this:

wBTC Address: bcrt1qdr7sjgtnudda8zrfklw8l5cnrxum5hns7e46hf
Factory Address (Regtest): bcrt1qxtpreq8zg7pp9wm550kjrhaa2r5kj6lhph9he5
Factory Address (Fractal): bc1qr4g85824m58wu0zffjtnf56n425fp0e8azhc7q
Router Address (Regtest): bcrt1qplnz54sca73t8a03nh494jatr9ffjg6ecarrj8
Router Address (Fractal): bc1q9w2zvmkzlezt2fu34u57y9vuw6rll5sp2090kn

Last updated