@btc-vision/transaction 1.0.89 → 1.0.90
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/README.md +3 -152
- package/browser/_version.d.ts +1 -1
- package/browser/index.js +1 -1
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/metadata/tokens.js +1 -1
- package/build/transaction/builders/TransactionBuilder.js +6 -3
- package/{Deploy.md → examples/Deploy.md} +2 -0
- package/{Unwrap.md → examples/Unwrap.md} +2 -0
- package/{Wrap.md → examples/Wrap.md} +2 -0
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/transaction/builders/TransactionBuilder.ts +8 -4
package/README.md
CHANGED
|
@@ -50,6 +50,8 @@ of the repository.
|
|
|
50
50
|
|
|
51
51
|
## Deployments, Wrapping and Unwrapping
|
|
52
52
|
|
|
53
|
+
WARNING: POSSIBLY OUTDATED
|
|
54
|
+
|
|
53
55
|
To learn how to wrap and unwrap Bitcoin on OP_NET, please refer to
|
|
54
56
|
the [Wrap.md](https://github.com/btc-vision/transaction/blob/main/Wrap.md) guide.
|
|
55
57
|
|
|
@@ -61,158 +63,7 @@ the [Deploy.md](https://github.com/btc-vision/transaction/blob/main/Deploy.md) g
|
|
|
61
63
|
|
|
62
64
|
## Usage
|
|
63
65
|
|
|
64
|
-
|
|
65
|
-
The following example demonstrates how to create a wBTC transfer transaction.
|
|
66
|
-
|
|
67
|
-
### Import Statements
|
|
68
|
-
|
|
69
|
-
This section imports the necessary modules and libraries required for building and broadcasting transactions.
|
|
70
|
-
|
|
71
|
-
```typescript
|
|
72
|
-
import {
|
|
73
|
-
TransactionFactory,
|
|
74
|
-
IInteractionParameters,
|
|
75
|
-
FetchUTXOParams,
|
|
76
|
-
UTXO,
|
|
77
|
-
UTXOManager,
|
|
78
|
-
Wallet,
|
|
79
|
-
wBTC
|
|
80
|
-
} from '@btc-vision/transaction';
|
|
81
|
-
import { networks } from 'bitcoinjs-lib';
|
|
82
|
-
import { BitcoinRPC } from '@btc-vision/bsi-bitcoin-rpc';
|
|
83
|
-
import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
|
|
84
|
-
import { BitcoinNetwork } from '@btc-vision/bsi-common';
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### Setting Up configurations
|
|
88
|
-
|
|
89
|
-
We must provide the necessary configurations for the network, wallet, and RPC connection:
|
|
90
|
-
|
|
91
|
-
- The opnetNode variable is the URL of the OP_NET node.
|
|
92
|
-
- The Testnet variable contains the wallet address, public key, and private key.
|
|
93
|
-
- The config variable inside the testnet object contains the network, host, port, username, and password for the RPC
|
|
94
|
-
connection.
|
|
95
|
-
|
|
96
|
-
```typescript
|
|
97
|
-
const opnetNode: string = 'https://testnet.opnet.org';
|
|
98
|
-
const Testnet: NetworkInformation = {
|
|
99
|
-
wallet: {
|
|
100
|
-
address: '', // as BECH32
|
|
101
|
-
publicKey: '', // as HEX
|
|
102
|
-
privateKey: '', // as WIF
|
|
103
|
-
},
|
|
104
|
-
|
|
105
|
-
config: {
|
|
106
|
-
BITCOIND_NETWORK: BitcoinNetwork.TestNet, // Bitcoin network
|
|
107
|
-
BITCOIND_HOST: '', // Bitcoin RPC host
|
|
108
|
-
BITCOIND_PORT: 9242, // Bitcoin RPC port
|
|
109
|
-
|
|
110
|
-
BITCOIND_USERNAME: '', // Bitcoin RPC username
|
|
111
|
-
BITCOIND_PASSWORD: '', // Bitcoin RPC password
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
### Setting Up the Network and RPC
|
|
117
|
-
|
|
118
|
-
This section sets up the network, RPC, and wallet instances required for the transaction.
|
|
119
|
-
|
|
120
|
-
```typescript
|
|
121
|
-
// Set up the network, RPC, and wallet
|
|
122
|
-
const network: networks.Network = networks.testnet; // Network
|
|
123
|
-
const rpc: BitcoinRPC = new BitcoinRPC();
|
|
124
|
-
const wBtc: wBTC = new wBTC(network); // wBTC metadata
|
|
125
|
-
|
|
126
|
-
const wallet: Wallet = new Wallet(Regtest.wallet, network); // Wallet
|
|
127
|
-
const utxoManager: UTXOManager = new UTXOManager(opnetNode); // UTXO manager
|
|
128
|
-
|
|
129
|
-
const factory: TransactionFactory = new TransactionFactory(); // Transaction factory
|
|
130
|
-
const abiCoder: ABICoder = new ABICoder();
|
|
131
|
-
const transferSelector = Number(`0x` + abiCoder.encodeSelector('transfer')); // Selector for the transfer function
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
### Creating Transfer Calldata
|
|
135
|
-
|
|
136
|
-
This section demonstrates how to create the calldata required for the `transfer` function.
|
|
137
|
-
|
|
138
|
-
```typescript
|
|
139
|
-
// Function to create the transfer calldata
|
|
140
|
-
function getTransferToCalldata(to: string, amount: bigint): Buffer {
|
|
141
|
-
const addCalldata: BinaryWriter = new BinaryWriter();
|
|
142
|
-
addCalldata.writeSelector(transferSelector);
|
|
143
|
-
addCalldata.writeAddress(to);
|
|
144
|
-
addCalldata.writeU256(amount);
|
|
145
|
-
return Buffer.from(addCalldata.getBuffer());
|
|
146
|
-
}
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
### Initializing and Fetching UTXOs
|
|
150
|
-
|
|
151
|
-
This section initializes the RPC connection and fetches UTXOs for the wallet.
|
|
152
|
-
|
|
153
|
-
```typescript
|
|
154
|
-
|
|
155
|
-
await rpc.init(Testnet.config); // Initialize the RPC connection
|
|
156
|
-
|
|
157
|
-
// Fetch UTXOs for the wallet
|
|
158
|
-
const utxoSetting: FetchUTXOParams = {
|
|
159
|
-
address: wallet.p2wpkh,
|
|
160
|
-
minAmount: 10000n,
|
|
161
|
-
requestedAmount: 100000n,
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
const utxos: UTXO[] = await utxoManager.fetchUTXO(utxoSetting);
|
|
165
|
-
console.log(`UTXOs:`, utxos);
|
|
166
|
-
|
|
167
|
-
if (!utxos.length) {
|
|
168
|
-
throw new Error('No UTXOs found');
|
|
169
|
-
}
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
### Preparing and Signing the Transaction
|
|
173
|
-
|
|
174
|
-
This section prepares the interaction parameters and signs the transaction.
|
|
175
|
-
|
|
176
|
-
```typescript
|
|
177
|
-
// Prepare the interaction parameters for the transaction
|
|
178
|
-
const amountToSend: bigint = 5000000n; // Amount to send
|
|
179
|
-
const calldata: Buffer = getTransferToCalldata(wBtc.getAddress(), amountToSend);
|
|
180
|
-
const interactionParameters: IInteractionParameters = {
|
|
181
|
-
from: wallet.p2wpkh, // From address
|
|
182
|
-
to: wBtc.getAddress(), // To address
|
|
183
|
-
utxos: utxos, // UTXOs
|
|
184
|
-
signer: wallet.keypair, // Signer
|
|
185
|
-
network: network, // Network
|
|
186
|
-
feeRate: 150, // Fee rate (satoshi per byte)
|
|
187
|
-
priorityFee: 50000n, // Priority fee (opnet)
|
|
188
|
-
calldata: calldata, // Calldata
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
// Sign and broadcast the transaction
|
|
192
|
-
const finalTx = factory.signInteraction(interactionParameters);
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
### Broadcasting the Transaction
|
|
196
|
-
|
|
197
|
-
This section broadcasts the signed transaction to the network.
|
|
198
|
-
|
|
199
|
-
```typescript
|
|
200
|
-
const firstTxBroadcast = await rpc.sendRawTransaction({ hexstring: finalTx[0] });
|
|
201
|
-
console.log(`First transaction broadcasted: ${firstTxBroadcast}`);
|
|
202
|
-
|
|
203
|
-
if (!firstTxBroadcast) {
|
|
204
|
-
throw new Error('Could not broadcast first transaction');
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const secondTxBroadcast = await rpc.sendRawTransaction({ hexstring: finalTx[1] });
|
|
208
|
-
console.log(`Second transaction broadcasted: ${secondTxBroadcast}`);
|
|
209
|
-
|
|
210
|
-
if (!secondTxBroadcast) {
|
|
211
|
-
throw new Error('Could not broadcast second transaction');
|
|
212
|
-
}
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
That's it! You have successfully created and broadcasted a transaction using OP_NET.
|
|
66
|
+
OUTDATED EXAMPLE. New examples will be added soon.
|
|
216
67
|
|
|
217
68
|
## Contribution
|
|
218
69
|
|
package/browser/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.0.
|
|
1
|
+
export declare const version = "1.0.90";
|