This repository was archived by the owner on Jul 28, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtransfer.mjs
More file actions
86 lines (73 loc) · 3.31 KB
/
Copy pathtransfer.mjs
File metadata and controls
86 lines (73 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* Transfer example: 2 wallets (2 mnemonics), 1 witness receive + 1 blind receive, refresh, listTransfers.
*
* Assumes UTXOs and asset already exist (e.g. from create-utxos-asset.mjs); wallets must be funded.
* - Wallet A (sender): init, send to B (witness + blind).
* - Wallet B (receiver): init, witnessReceive + blindReceive (invoices).
* - Both: refreshWallet(), listTransfers(assetId).
*
* ASSET_ID="rgb:..." MNEMONIC_A="..." MNEMONIC_B="..." node examples/transfer.mjs
*/
import { UTEXOWallet } from '../dist/index.mjs';
const NETWORK = 'testnet';
const MNEMONIC_A = process.env.MNEMONIC_A || 'hybrid fame undo length tennis field cruel income media memory embrace reason';
const MNEMONIC_B = process.env.MNEMONIC_B || 'slab deliver medal play immune enact drink inch okay pledge unknown stable';
const ASSET_ID = process.env.ASSET_ID||'rgb:bOJpeaL1-4Og2TYO-z8hsInv-qTMH3Lj-AGuhVJ5-kAveVAM';
if (!ASSET_ID) {
console.error('ASSET_ID is required (e.g. from create-utxos-asset.mjs output)');
process.exit(1);
}
async function main() {
console.log('--- Transfer: 2 wallets, witness + blind receive ---');
console.log('Network:', NETWORK);
console.log('Asset:', ASSET_ID);
const walletA = new UTEXOWallet(MNEMONIC_A, { network: NETWORK });
const walletB = new UTEXOWallet(MNEMONIC_B, { network: NETWORK });
try {
await walletA.initialize();
await walletB.initialize();
await walletB.refreshWallet();
await walletA.refreshWallet();
console.log('Wallet A address:', await walletA.getAddress());
console.log('Wallet B address:', await walletB.getAddress());
const amountWitness = 10;
const amountBlind = 20;
const invWitness = await walletB.witnessReceive({ amount: amountWitness });
console.log('Wallet B witness invoice created',invWitness);
const sendWitness = await walletA.send({
invoice: invWitness.invoice,
assetId: ASSET_ID,
amount: amountWitness,
witnessData: { amountSat: 1000 },
});
console.log('Witness transfer sent:', sendWitness);
const invBlind = await walletB.blindReceive({ amount: amountBlind });
console.log('Wallet B blind invoice created',invBlind);
const sendBlind = await walletA.send({
invoice: invBlind.invoice,
assetId: ASSET_ID,
amount: amountBlind,
});
console.log('Blind transfer sent:', sendBlind);
await walletB.refreshWallet();
// // delay for 10 seconds
await new Promise(resolve => setTimeout(resolve, 120000));
console.log('wait 3 confirmations');
await walletB.refreshWallet();
await walletA.refreshWallet();
const transfersA = await walletA.listTransfers(ASSET_ID); // sent stansfer should be settled
const transfersB = await walletB.listTransfers(ASSET_ID); // received transfer should be settled
console.log('Wallet A listTransfers:', transfersA.length, transfersA);
console.log('allet B listTransfers:', transfersB.length, transfersB);
} finally {
await walletA.dispose();
await walletB.dispose();
}
console.log('Done.');
}
main()
.then(() => process.exit(0))
.catch((err) => {
console.error('Error:', err);
process.exit(1);
});