Introduction A complete, compact and simple library for the Bitcoin ecosystem, written in TypeScript. This library is designed to be easy to use and understand, while providing a comprehensive set of functions for creating, reading and manipulating Bitcoin transactions. This library is designed to be able to manipulate anything related to BSI (Bitcoin Smart Inscription), smart contracts, and other Bitcoin-related technologies.
Getting Started Prerequisites Node.js version 16.x or higher npm (Node Package Manager) Installation npm i opnet Copy Documentation Documentation available at https://dev.opnet.org or in the docs/ directory of the repository.
Development Clone the repository: git clone https://github.com/btc-vision/opnet.git Copy Navigate to the repository directory: cd opnet Copy Install the required dependencies: npm i Copy Example Calling a contract function from typescript/javascript is as simple as a few lines of code:
import { getContract, IOP20Contract, JSONRpcProvider, OP_20_ABI, TransactionParameters, } from 'opnet'; import { Configs } from '../configs/Configs.js'; import { Address, Wallet } from '@btc-vision/transaction'; import { Network } from '@btc-vision/bitcoin';
// You can also easily simulate & interact onchain!
const transferSimulation = await example.transfer(yourAddress, 10000n); const params: TransactionParameters = { signer: wallet.keypair, // The keypair that will sign the transaction refundTo: wallet.p2tr, // Refund the rest of the funds to this address maximumAllowedSatToSpend: 5000n, // The maximum we want to allocate to this transaction in satoshis feeRate: 10, // We need to provide a fee rate network: network, // The network we are operating on };
const tx = await transferSimulation.sendTransaction(params); console.log('Transaction created!', tx); Copy You can get the calldata generated by doing balanceExample.calldata and generate your transaction based on that. In scenarios where you are writing data on-chain, you must specify the sender in the getContract function. This is important for the simulation to pass.
Contribution Contributions are welcome! Please read through the CONTRIBUTING.md file for guidelines on how to submit issues, feature requests, and pull requests. We appreciate your input and encourage you to help us improve OP_NET.
License This project is open source and available under the MIT License. If you have any suggestions or contributions, please feel free to submit a pull request.