File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ const bitcoin = require ( 'bitcoinjs-lib' ) ;
2
+ const bip65 = require ( 'bip65' ) ;
3
+
4
+ // DLC setup
5
+ const oraclePublicKey = Buffer . from ( '...' , 'hex' ) ; // Oracle's public key
6
+ const counterpartiesPublicKeys = [
7
+ Buffer . from ( '...' , 'hex' ) , // Counterparty 1's public key
8
+ Buffer . from ( '...' , 'hex' ) // Counterparty 2's public key
9
+ ] ;
10
+ const outcomeHash = Buffer . from ( '...' , 'hex' ) ; // Outcome's hash
11
+ const fundingTransactionOutput = 'txid:vout' ; // Funding transaction's output
12
+
13
+ // RBF setup
14
+ const locktime = bip65 . encode ( { utc : 0 } ) ; // Use a locktime that allows RBF
15
+
16
+ // Create the DLC contract
17
+ const dlcContract = bitcoin . payments . embed ( { data : [ outcomeHash ] } ) ;
18
+
19
+ // Create the transaction
20
+ const tx = new bitcoin . TransactionBuilder ( ) ;
21
+ tx . addInput ( fundingTransactionOutput , 0 ) ;
22
+ tx . addOutput ( dlcContract . output , 0 ) ; // DLC output
23
+ tx . locktime = locktime ;
24
+ tx . enableRBF ( ) ; // Enable RBF
25
+
26
+ // Sign the transaction
27
+ tx . sign ( 0 , oraclePublicKey ) ;
28
+ counterpartiesPublicKeys . forEach ( ( publicKey ) => {
29
+ tx . sign ( 0 , publicKey ) ;
30
+ } ) ;
31
+
32
+ // Finalize the transaction
33
+ const finalTx = tx . build ( ) ;
34
+ console . log ( finalTx . toHex ( ) ) ;
You can’t perform that action at this time.
0 commit comments