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:
npminstall@btc-vision/transactionbitcoinjs-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 addressconstnetwork=bitcoinjs.networks.regtest; // Use regtest, testnet, or mainnetconstwbtcAddress=newwBTC(network).getAddress(); // Fetch the wBTC address for the given networkconsole.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 networksconstfactoryAddressRegtest=FACTORY_ADDRESS_REGTEST;constfactoryAddressFractal=FACTORY_ADDRESS_FRACTAL;constrouterAddressRegtest=ROUTER_ADDRESS_REGTEST;constrouterAddressFractal=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: