generated from jasonsturges/typescript-npm-package
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsend-op-return.ts
33 lines (26 loc) · 931 Bytes
/
send-op-return.ts
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
import { DraftTransactionConfig, OpReturn, SPVWalletUserAPI } from '../dist/typescript-npm-package.cjs.js';
import { exampleXPriv } from './example-keys.js';
import { errMessage } from './utils.js';
const server = 'http://localhost:3003';
if (!exampleXPriv) {
console.log(errMessage('xPriv'));
process.exit(1);
}
const client = new SPVWalletUserAPI(server, {
xPriv: exampleXPriv,
});
const opReturn: OpReturn = {
stringParts: ['hello', 'world'],
};
const transactionConfig: DraftTransactionConfig = {
outputs: [
{
opReturn: opReturn,
},
],
};
const draftTransaction = await client.draftTransaction(transactionConfig, {});
console.log('DraftTransaction response:', draftTransaction);
const finalized = await client.finalizeTransaction(draftTransaction);
const transaction = await client.recordTransaction(finalized, draftTransaction.id, {});
console.log('Transaction with OP_RETURN:', transaction);