UNPKG

@bsv/p2p

Version:

A client for P2P messaging and payments

54 lines 2.36 kB
import { WalletClient } from '@bsv/sdk'; import { MessageBoxClient } from './MessageBoxClient.js'; import * as crypto from 'crypto'; global.self = { crypto }; (async () => { const messageBoxClient = new MessageBoxClient({ walletClient: new WalletClient('auto', 'local'), // NOTE Fix bug host: 'https://staging-messagebox.babbage.systems', enableLogging: true }); // await messageBoxClient.init() const result = await messageBoxClient.listMessages({ messageBox: 'L3_inbox' }); console.log(result); // await messageBoxClient.acknowledgeMessage({ messageIds: [result[0].messageId] }) // const result = await messageBoxClient.sendMessage({ // recipient: '0350fa50d7c23f63d949c9532f41a7ea0c01112ffb1404cfb8a9f732b11a54a1ce', // messageBox: 'test_inbox', // body: { data: 'test' } // }) // console.log('Message sent successfully:', result) // const kv = new LocalKVStore(new WalletClient('auto', 'local')) // await kv.set('testKey', 'New value') // const value = await kv.get('testKey') // console.log('Value from local storage:', value) // const payloadNum = 1_234_567_890 // any number you like // const payloadBuf = Utils.toArray('HELLO WORLD', 'utf8') // 4-byte LE // const script = new Script() // .writeOpCode(OP.OP_FALSE) // 0x00 // .writeOpCode(OP.OP_RETURN) // 0x6a // .writeBin(payloadBuf) // push your data // // --------------------------------------------------------------------------- // // 2. Fund, sign and broadcast with WalletClient // // ('auto' = pick current network, 'local' = talk to kernel at localhost:3301) // // --------------------------------------------------------------------------- // const wc = new WalletClient('auto', 'local') // const { txid } = await wc.createAction({ // description: 'Data test', // outputs: [ // { // lockingScript: script.toHex(), // <-- correct field name // satoshis: 0, // outputDescription: 'test' // } // ], // options: { // acceptDelayedBroadcast: false, // randomizeOutputs: false // } // }) // console.log('Transaction ID:', txid) })(); //# sourceMappingURL=sendMessageTest.js.map