The official client library for building Bitcoin-based applications on OPNet. Full TypeScript support with type-safe contract interactions.
npm install opnet @btc-vision/transaction @btc-vision/bitcoinCheck out the full documentation in /docs!
- Getting Started
- Providers - JSON-RPC & WebSocket connections
- Smart Contracts - Contract interactions & transactions
- UTXO Management - Bitcoin UTXO handling
- Offline Signing - Cold wallet support
- ABI Reference - OP20, OP721, MotoSwap ABIs
- API Reference - Full API documentation
| Network | URL |
|---|---|
| Mainnet | https://mainnet.opnet.org |
| Regtest | https://regtest.opnet.org |
import { BitcoinUtils, getContract, IOP20Contract, JSONRpcProvider, OP_20_ABI } from 'opnet';
import { AddressTypes, Mnemonic, MLDSASecurityLevel } from '@btc-vision/transaction';
import { networks } from '@btc-vision/bitcoin';
// Connect to OPNet
const provider = new JSONRpcProvider('https://regtest.opnet.org', networks.regtest);
// Create wallet from mnemonic
const mnemonic = new Mnemonic(
'your twenty four word seed phrase goes here ...',
'',
networks.regtest,
MLDSASecurityLevel.LEVEL2,
);
const wallet = mnemonic.deriveUnisat(AddressTypes.P2TR, 0);
const myAddress = wallet.address;
// Interact with a token contract
const token = getContract<IOP20Contract>(
'op1...', // contract address
OP_20_ABI,
provider,
networks.regtest,
myAddress
);
// Read token info
const name = await token.name();
const balance = await token.balanceOf(myAddress);
console.log('Token:', name.properties.name);
console.log('Balance:', balance.properties.balance);
// Send a transaction (100 tokens with 8 decimals)
const amount = BitcoinUtils.expandToDecimals(100, 8);
const simulation = await token.transfer(recipientAddress, amount);
if (simulation.revert) {
throw new Error(`Transfer would fail: ${simulation.revert}`);
}
const tx = await simulation.sendTransaction({
signer: wallet.keypair,
mldsaSigner: wallet.mldsaKeypair,
refundTo: wallet.p2tr,
maximumAllowedSatToSpend: 50000n,
feeRate: 10,
network: networks.regtest,
});
console.log('TX ID:', tx.transactionId);- Node.js >= 24.0.0
- TypeScript >= 5.9
git clone https://github.com/btc-vision/opnet.git
cd opnet
npm install
npm run buildContributions welcome! See CONTRIBUTING.md for guidelines.