@btc-vision/transaction 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Deploy.md +186 -0
- package/README.md +5 -0
- package/Wrap.md +192 -0
- package/browser/_version.d.ts +1 -1
- package/browser/index.js +1 -1
- package/browser/opnet.d.ts +6 -1
- package/browser/tests/deploy.d.ts +1 -0
- package/browser/tests/wrap.d.ts +1 -0
- package/browser/tests/wrapTest.d.ts +1 -0
- package/browser/transaction/TransactionFactory.d.ts +15 -1
- package/browser/transaction/builders/DeploymentTransaction.d.ts +40 -0
- package/browser/transaction/builders/InteractionTransaction.d.ts +2 -35
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +46 -0
- package/browser/transaction/builders/TransactionBuilder.d.ts +8 -1
- package/browser/transaction/builders/WrapTransaction.d.ts +27 -0
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +16 -12
- package/browser/utils/BitcoinUtils.d.ts +1 -0
- package/browser/utxo/OPNetLimitedProvider.d.ts +10 -0
- package/browser/wbtc/Generate.d.ts +13 -0
- package/browser/wbtc/WrappedGenerationParameters.d.ts +11 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/opnet.d.ts +6 -1
- package/build/opnet.js +6 -1
- package/build/tests/deploy.d.ts +1 -0
- package/build/tests/deploy.js +60 -0
- package/build/tests/test.js +3 -3
- package/build/tests/transfer.js +2 -2
- package/build/tests/wrap.d.ts +1 -0
- package/build/tests/wrap.js +64 -0
- package/build/tests/wrapTest.d.ts +1 -0
- package/build/tests/wrapTest.js +64 -0
- package/build/tests/wrapTestg.d.ts +1 -0
- package/build/tests/wrapTestg.js +66 -0
- package/build/transaction/TransactionFactory.d.ts +15 -1
- package/build/transaction/TransactionFactory.js +68 -0
- package/build/transaction/builders/DeploymentTransaction.d.ts +40 -0
- package/build/transaction/builders/DeploymentTransaction.js +216 -0
- package/build/transaction/builders/FundingTransaction.js +4 -1
- package/build/transaction/builders/InteractionTransaction.d.ts +2 -35
- package/build/transaction/builders/InteractionTransaction.js +4 -207
- package/build/transaction/builders/SharedInteractionTransaction.d.ts +46 -0
- package/build/transaction/builders/SharedInteractionTransaction.js +213 -0
- package/build/transaction/builders/TransactionBuilder.d.ts +8 -1
- package/build/transaction/builders/TransactionBuilder.js +19 -11
- package/build/transaction/builders/WrapTransaction.d.ts +27 -0
- package/build/transaction/builders/WrapTransaction.js +132 -0
- package/build/transaction/interfaces/ITransactionParameters.d.ts +16 -12
- package/build/utils/BitcoinUtils.d.ts +1 -0
- package/build/utils/BitcoinUtils.js +7 -0
- package/build/utxo/OPNetLimitedProvider.d.ts +10 -0
- package/build/utxo/OPNetLimitedProvider.js +85 -0
- package/build/utxo/OPNetUtils.d.ts +7 -0
- package/build/utxo/OPNetUtils.js +47 -0
- package/build/verification/TapscriptVerificator.js +3 -3
- package/build/wbtc/Generate.d.ts +13 -0
- package/build/wbtc/Generate.js +1 -0
- package/build/wbtc/WrappedGenerationParameters.d.ts +11 -0
- package/build/wbtc/WrappedGenerationParameters.js +16 -0
- package/bytecode/contract.wasm +0 -0
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/AddressGenerator.html +2 -2
- package/docs/classes/BitcoinUtils.html +7 -3
- package/docs/classes/CalldataGenerator.html +10 -10
- package/docs/classes/Compressor.html +4 -4
- package/docs/classes/ContractBaseMetadata.html +4 -4
- package/docs/classes/DeploymentGenerator.html +9 -9
- package/docs/classes/DeploymentTransaction.html +368 -0
- package/docs/classes/EcKeyPair.html +16 -16
- package/docs/classes/FundingTransaction.html +50 -47
- package/docs/classes/Generator.html +9 -9
- package/docs/classes/InteractionTransaction.html +89 -109
- package/docs/classes/OPNetLimitedProvider.html +197 -0
- package/docs/classes/SharedInteractionTransaction.html +392 -0
- package/docs/classes/TapscriptVerificator.html +2 -2
- package/docs/classes/TransactionBuilder.html +53 -50
- package/docs/classes/TransactionFactory.html +11 -4
- package/docs/classes/TweakedSigner.html +2 -2
- package/docs/classes/Wallet.html +10 -10
- package/docs/classes/WrapTransaction.html +404 -0
- package/docs/classes/WrappedGeneration.html +187 -0
- package/docs/classes/wBTC.html +7 -7
- package/docs/enums/TransactionSequence.html +177 -0
- package/docs/enums/TransactionType.html +2 -2
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +3 -1
- package/docs/interfaces/ContractAddressVerificationParams.html +2 -2
- package/docs/interfaces/DeploymentResult.html +177 -0
- package/docs/interfaces/FetchUTXOParams.html +2 -2
- package/docs/interfaces/GenerationConstraints.html +182 -0
- package/docs/interfaces/IDeploymentParameters.html +183 -0
- package/docs/interfaces/IFundingTransactionParameters.html +3 -3
- package/docs/interfaces/IInteractionParameters.html +4 -6
- package/docs/interfaces/ITransactionParameters.html +3 -3
- package/docs/interfaces/IWallet.html +4 -4
- package/docs/interfaces/IWrapParameters.html +186 -0
- package/docs/interfaces/NetworkInformation.html +2 -2
- package/docs/interfaces/PsbtInputExtended.html +1 -1
- package/docs/interfaces/PsbtOutputExtendedAddress.html +2 -2
- package/docs/interfaces/PsbtOutputExtendedScript.html +2 -2
- package/docs/interfaces/RawUTXOResponse.html +2 -2
- package/docs/interfaces/SharedInteractionParameters.html +183 -0
- package/docs/interfaces/TapLeafScript.html +2 -2
- package/docs/interfaces/TweakSettings.html +3 -3
- package/docs/interfaces/UTXO.html +2 -2
- package/docs/interfaces/UpdateInput.html +2 -2
- package/docs/interfaces/WrapResult.html +178 -0
- package/docs/interfaces/WrappedGenerationParameters.html +184 -0
- package/docs/modules.html +14 -4
- package/docs/types/PsbtOutputExtended.html +1 -1
- package/docs/variables/version.html +1 -1
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/opnet.ts +8 -1
- package/src/tests/deploy.ts +81 -0
- package/src/tests/test.ts +3 -3
- package/src/tests/transfer.ts +2 -2
- package/src/tests/wrap.ts +89 -0
- package/src/tests/wrapTest.ts +88 -0
- package/src/transaction/TransactionFactory.ts +119 -1
- package/src/transaction/builders/DeploymentTransaction.ts +418 -0
- package/src/transaction/builders/FundingTransaction.ts +5 -1
- package/src/transaction/builders/InteractionTransaction.ts +5 -404
- package/src/transaction/builders/SharedInteractionTransaction.ts +432 -0
- package/src/transaction/builders/TransactionBuilder.ts +40 -15
- package/src/transaction/builders/WrapTransaction.ts +286 -0
- package/src/transaction/interfaces/ITransactionParameters.ts +20 -13
- package/src/utils/BitcoinUtils.ts +16 -0
- package/src/utxo/{UTXOManager.ts → OPNetLimitedProvider.ts} +53 -2
- package/src/verification/TapscriptVerificator.ts +3 -3
- package/src/wbtc/Generate.ts +30 -0
- package/src/wbtc/WrappedGenerationParameters.ts +33 -0
- package/tests/TransactionBuilder.test.ts +58 -58
- package/docs/classes/UTXOManager.html +0 -187
- package/docs/interfaces/ITransactionDataContractDeployment.html +0 -184
- package/docs/interfaces/ITransactionDataContractInteractionWrap.html +0 -186
package/Deploy.md
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Deploying a Smart Contract on OPNet
|
|
2
|
+
|
|
3
|
+
This guide will walk you through the process of deploying a smart contract on the OPNet protocol. OPNet allows for the
|
|
4
|
+
execution of smart contracts on the Bitcoin network, leveraging the security and stability of Bitcoin.
|
|
5
|
+
|
|
6
|
+
## Prerequisites
|
|
7
|
+
|
|
8
|
+
- Node.js and npm installed
|
|
9
|
+
- Bitcoin regtest wallet
|
|
10
|
+
- Access to an OPNet node
|
|
11
|
+
- Bitcoin RPC configured for regtest
|
|
12
|
+
- Contract bytecode in WebAssembly format
|
|
13
|
+
|
|
14
|
+
## Setup
|
|
15
|
+
|
|
16
|
+
First, ensure you have the necessary dependencies installed in your project:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm i
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Step-by-Step Guide
|
|
23
|
+
|
|
24
|
+
### 1. Import Required Libraries
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { Wallet } from '../keypair/Wallet.js';
|
|
28
|
+
import { OPNetLimitedProvider } from '../utxo/OPNetLimitedProvider.js';
|
|
29
|
+
import { networks, Network } from 'bitcoinjs-lib';
|
|
30
|
+
import { TransactionFactory } from '../transaction/TransactionFactory.js';
|
|
31
|
+
import { BitcoinRPC } from '@btc-vision/bsi-bitcoin-rpc';
|
|
32
|
+
import { IDeploymentParameters } from '../transaction/interfaces/ITransactionParameters.js';
|
|
33
|
+
import { FetchUTXOParams, UTXO } from '../utxo/interfaces/IUTXO.js';
|
|
34
|
+
import * as fs from 'fs';
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Setting Up configurations
|
|
38
|
+
|
|
39
|
+
We must provide the necessary configurations for the network, wallet, and RPC connection:
|
|
40
|
+
|
|
41
|
+
- The opnetNode variable is the URL of the OP_NET node.
|
|
42
|
+
- The Testnet variable contains the wallet address, public key, and private key.
|
|
43
|
+
- The config variable inside the testnet object contains the network, host, port, username, and password for the RPC
|
|
44
|
+
connection.
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
const network: Network = networks.testnet;
|
|
48
|
+
const opnetNode: string = 'https://testnet.opnet.org';
|
|
49
|
+
const Testnet: NetworkInformation = {
|
|
50
|
+
wallet: {
|
|
51
|
+
address: '', // as BECH32
|
|
52
|
+
publicKey: '', // as HEX
|
|
53
|
+
privateKey: '', // as WIF
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
config: {
|
|
57
|
+
BITCOIND_NETWORK: BitcoinNetwork.TestNet, // Bitcoin network
|
|
58
|
+
BITCOIND_HOST: '', // Bitcoin RPC host
|
|
59
|
+
BITCOIND_PORT: 9242, // Bitcoin RPC port
|
|
60
|
+
|
|
61
|
+
BITCOIND_USERNAME: '', // Bitcoin RPC username
|
|
62
|
+
BITCOIND_PASSWORD: '', // Bitcoin RPC password
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 2. Initialize Network and RPC
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
const rpc: BitcoinRPC = new BitcoinRPC();
|
|
71
|
+
const wallet: Wallet = new Wallet(Testnet.wallet, network);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 3. Connect to OPNet
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
const utxoManager: OPNetLimitedProvider = new OPNetLimitedProvider(opnetNode);
|
|
78
|
+
const factory: TransactionFactory = new TransactionFactory();
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 4. Mining a Block (Optional)
|
|
82
|
+
|
|
83
|
+
If you are using a regtest or need to mine a block to proceed:
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
const shouldMineBlock: boolean = true;
|
|
87
|
+
|
|
88
|
+
async function mineBlock(): Promise<boolean> {
|
|
89
|
+
const ok = await rpc.generateToAddress(1, wallet.p2wpkh, 'default');
|
|
90
|
+
if (!ok) {
|
|
91
|
+
throw new Error('Could not mine block');
|
|
92
|
+
}
|
|
93
|
+
console.log(`Mined block`, ok);
|
|
94
|
+
return !!ok.length;
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 5. Initialize RPC with Testnet Configuration
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
await rpc.init(Testnet.config);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### 6. Define UTXO Settings and Fetch UTXOs
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
const utxoSetting: FetchUTXOParams = {
|
|
108
|
+
address: wallet.p2wpkh,
|
|
109
|
+
minAmount: 10000n,
|
|
110
|
+
requestedAmount: 100000n,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const utxos: UTXO[] = await utxoManager.fetchUTXO(utxoSetting);
|
|
114
|
+
if (!utxos) {
|
|
115
|
+
throw new Error('No UTXOs found');
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### 7. Read Contract Bytecode
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
const bytecode = fs.readFileSync('./bytecode/contract.wasm');
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### 8. Create Deployment Parameters and Finalize Transaction
|
|
126
|
+
|
|
127
|
+
Let's create the deployment parameters and finalize the transaction:
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
const deploymentParameters: IDeploymentParameters = {
|
|
131
|
+
from: wallet.p2wpkh,
|
|
132
|
+
utxos: utxos,
|
|
133
|
+
signer: wallet.keypair,
|
|
134
|
+
network: network,
|
|
135
|
+
feeRate: 150,
|
|
136
|
+
priorityFee: 50000n,
|
|
137
|
+
bytecode: bytecode,
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const finalTx = factory.signDeployment(deploymentParameters);
|
|
141
|
+
console.log(`Final transaction:`, finalTx);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### 9. Broadcast the Transactions
|
|
145
|
+
|
|
146
|
+
Broadcast the transactions to the network:
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
const firstTxBroadcast = await rpc.sendRawTransaction({
|
|
150
|
+
hexstring: finalTx.transaction[0],
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
console.log(`First transaction broadcasted: ${firstTxBroadcast}`);
|
|
154
|
+
|
|
155
|
+
if (!firstTxBroadcast) {
|
|
156
|
+
throw new Error('Could not broadcast first transaction');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const secondTxBroadcast = await rpc.sendRawTransaction({
|
|
160
|
+
hexstring: finalTx.transaction[1],
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
console.log(`Second transaction broadcasted: ${secondTxBroadcast}`);
|
|
164
|
+
|
|
165
|
+
if (!secondTxBroadcast) {
|
|
166
|
+
throw new Error('Could not broadcast second transaction');
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### 10. (Optional) Mine a Block
|
|
171
|
+
|
|
172
|
+
If you need to mine a block after broadcasting the transactions:
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
if (shouldMineBlock) {
|
|
176
|
+
await mineBlock();
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Conclusion
|
|
181
|
+
|
|
182
|
+
You have now successfully deployed a smart contract on the OPNet protocol. This contract can interact with the Bitcoin
|
|
183
|
+
network, enabling complex functionalities and decentralized applications.
|
|
184
|
+
|
|
185
|
+
For any further questions or issues, please refer to the official documentation or reach out to the community for
|
|
186
|
+
support.
|
package/README.md
CHANGED
|
@@ -48,6 +48,11 @@ of the repository.
|
|
|
48
48
|
npm i
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
+
## Deployments and Wrapping
|
|
52
|
+
|
|
53
|
+
To learn how to wrap and unwrap Bitcoin on OP_NET, please refer to the [Wrap.md](./Wrap.md) guide.
|
|
54
|
+
To learn how to deploy smart contracts on OP_NET, please refer to the [Deploy.md](./Deploy.md) guide.
|
|
55
|
+
|
|
51
56
|
## Usage
|
|
52
57
|
|
|
53
58
|
Here's a basic example of how to use the OP_NET Transaction Builder library to create and sign a transaction:
|
package/Wrap.md
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# Wrapping Bitcoin (wBTC) Guide
|
|
2
|
+
|
|
3
|
+
This guide will walk you through the process of wrapping Bitcoin (wBTC) using the OPNet protocol. Wrapping Bitcoin
|
|
4
|
+
allows you to use Bitcoin in smart contracts, similar to how ERC-20 tokens are used on Ethereum.
|
|
5
|
+
|
|
6
|
+
## What is wBTC?
|
|
7
|
+
|
|
8
|
+
wBTC (Wrapped Bitcoin) is an OP_0 token backed 1:1 with Bitcoin. It enables Bitcoin holders
|
|
9
|
+
to participate in decentralized finance (DeFi) applications, offering greater liquidity and integration within the
|
|
10
|
+
Bitcoin ecosystem. By wrapping Bitcoin, users can leverage their BTC in a broader range of financial services while
|
|
11
|
+
retaining the value and stability of Bitcoin.
|
|
12
|
+
|
|
13
|
+
## Preview
|
|
14
|
+
|
|
15
|
+
You can check your wBTC balance at anytime via [wbtc.opnet.org](https://wbtc.opnet.org).
|
|
16
|
+
|
|
17
|
+
## Prerequisites
|
|
18
|
+
|
|
19
|
+
- Node.js and npm installed
|
|
20
|
+
- Bitcoin testnet wallet
|
|
21
|
+
- Access to an OPNet node
|
|
22
|
+
- Bitcoin RPC configured for testnet
|
|
23
|
+
|
|
24
|
+
## Setup
|
|
25
|
+
|
|
26
|
+
First, ensure you have the necessary dependencies installed in your project:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
npm i
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Step-by-Step Guide
|
|
33
|
+
|
|
34
|
+
### 1. Import Required Libraries
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { Wallet } from '../keypair/Wallet.js';
|
|
38
|
+
import { OPNetLimitedProvider } from '../utxo/OPNetLimitedProvider.js';
|
|
39
|
+
import { networks, Network } from 'bitcoinjs-lib';
|
|
40
|
+
import { TransactionFactory } from '../transaction/TransactionFactory.js';
|
|
41
|
+
import { BitcoinRPC } from '@btc-vision/bsi-bitcoin-rpc';
|
|
42
|
+
import { IWrapParameters } from '../transaction/interfaces/ITransactionParameters.js';
|
|
43
|
+
import { FetchUTXOParams, UTXO } from '../utxo/interfaces/IUTXO.js';
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Setting Up configurations
|
|
47
|
+
|
|
48
|
+
We must provide the necessary configurations for the network, wallet, and RPC connection:
|
|
49
|
+
|
|
50
|
+
- The opnetNode variable is the URL of the OP_NET node.
|
|
51
|
+
- The Testnet variable contains the wallet address, public key, and private key.
|
|
52
|
+
- The config variable inside the testnet object contains the network, host, port, username, and password for the RPC
|
|
53
|
+
connection.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
const network: Network = networks.testnet;
|
|
57
|
+
const opnetNode: string = 'https://testnet.opnet.org';
|
|
58
|
+
const Testnet: NetworkInformation = {
|
|
59
|
+
wallet: {
|
|
60
|
+
address: '', // as BECH32
|
|
61
|
+
publicKey: '', // as HEX
|
|
62
|
+
privateKey: '', // as WIF
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
config: {
|
|
66
|
+
BITCOIND_NETWORK: BitcoinNetwork.TestNet, // Bitcoin network
|
|
67
|
+
BITCOIND_HOST: '', // Bitcoin RPC host
|
|
68
|
+
BITCOIND_PORT: 9242, // Bitcoin RPC port
|
|
69
|
+
|
|
70
|
+
BITCOIND_USERNAME: '', // Bitcoin RPC username
|
|
71
|
+
BITCOIND_PASSWORD: '', // Bitcoin RPC password
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 2. Initialize Network and RPC
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
const rpc: BitcoinRPC = new BitcoinRPC();
|
|
80
|
+
const wallet: Wallet = new Wallet(Testnet.wallet, network);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 3. Connect to OPNet
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
const opnet: OPNetLimitedProvider = new OPNetLimitedProvider(opnetNode);
|
|
87
|
+
const factory: TransactionFactory = new TransactionFactory();
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 4. Mining a Block (Optional)
|
|
91
|
+
|
|
92
|
+
If you are using a regtest or need to mine a block to proceed:
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
const shouldMineBlock: boolean = true;
|
|
96
|
+
|
|
97
|
+
async function mineBlock(): Promise<boolean> {
|
|
98
|
+
const ok = await rpc.generateToAddress(1, wallet.p2wpkh, 'default');
|
|
99
|
+
if (!ok) {
|
|
100
|
+
throw new Error('Could not mine block');
|
|
101
|
+
}
|
|
102
|
+
console.log(`Mined block`, ok);
|
|
103
|
+
return !!ok.length;
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### 5. Initialize RPC with Testnet Configuration
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
await rpc.init(Testnet.config);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 6. Define Wrap Amount and Fetch UTXOs
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
const wrapAmount: bigint = 100000000n; // 1 BTC in satoshis
|
|
117
|
+
const utxoSetting: FetchUTXOParams = {
|
|
118
|
+
address: wallet.p2wpkh,
|
|
119
|
+
minAmount: 10000n,
|
|
120
|
+
requestedAmount: wrapAmount,
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const utxos: UTXO[] = await opnet.fetchUTXO(utxoSetting);
|
|
124
|
+
if (!utxos) {
|
|
125
|
+
throw new Error('No UTXOs found');
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### 7. Fetch Wrap Parameters
|
|
130
|
+
|
|
131
|
+
This will fetch the parameters required for wrapping Bitcoin into WBTC. If no parameters are found, an error will be
|
|
132
|
+
thrown.
|
|
133
|
+
This step is very important as it provides the necessary information for the wrapping process.
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
const generationParameters = await opnet.fetchWrapParameters(wrapAmount);
|
|
137
|
+
if (!generationParameters) {
|
|
138
|
+
throw new Error('No generation parameters found');
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### 8. Create Wrap Parameters and Finalize Transaction
|
|
143
|
+
|
|
144
|
+
Now, we will create the wrap parameters and finalize the transaction using the TransactionFactory.
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
const wrapParameters: IWrapParameters = {
|
|
148
|
+
from: wallet.p2wpkh,
|
|
149
|
+
utxos: utxos,
|
|
150
|
+
signer: wallet.keypair,
|
|
151
|
+
network: network,
|
|
152
|
+
feeRate: 350,
|
|
153
|
+
priorityFee: 50000n,
|
|
154
|
+
amount: wrapAmount,
|
|
155
|
+
generationParameters: generationParameters,
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const finalTx = factory.wrap(wrapParameters);
|
|
159
|
+
console.log(`Final transaction:`, finalTx);
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### 9. Broadcast the Transactions
|
|
163
|
+
|
|
164
|
+
To broadcast the transactions, we will send the raw transactions to the network.
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
const firstTxBroadcast = await rpc.sendRawTransaction({
|
|
168
|
+
hexstring: finalTx.transaction[0],
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
console.log(`First transaction broadcasted: ${firstTxBroadcast}`);
|
|
172
|
+
|
|
173
|
+
if (!firstTxBroadcast) {
|
|
174
|
+
throw new Error('Could not broadcast first transaction');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const secondTxBroadcast = await rpc.sendRawTransaction({
|
|
178
|
+
hexstring: finalTx.transaction[1],
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
console.log(`Second transaction broadcasted: ${secondTxBroadcast}`);
|
|
182
|
+
|
|
183
|
+
if (!secondTxBroadcast) {
|
|
184
|
+
throw new Error('Could not broadcast second transaction');
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Conclusion
|
|
189
|
+
|
|
190
|
+
You have now successfully wrapped Bitcoin into WBTC using the OPNet protocol!
|
|
191
|
+
For any further questions or issues, please refer to the official documentation or reach out to the community for
|
|
192
|
+
support.
|
package/browser/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.0.
|
|
1
|
+
export declare const version = "1.0.8";
|