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 opnet bitcoinjs-lib
# or
yarn add opnet 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 which is included in the opnet 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: bcrt1qamv2ejattjgsc6k3yf3zqrp0wpuyedqgjmwx0v
Factory Address (Regtest): bcrt1q9pf9fnpch9z2qrp5e3dgr2avzu3mypq3km2k40
Factory Address (Fractal): bc1qr4g85824m58wu0zffjtnf56n425fp0e8azhc7q
Router Address (Regtest): bcrt1q9yd6mk324k0q4krmlxjky0pk65ul6hkf4u35e6
Router Address (Fractal): bc1q9w2zvmkzlezt2fu34u57y9vuw6rll5sp2090kn

Last updated