@pulsechain/msgboard
TypeScript icon, indicating that this package has built-in type declarations

0.0.28 • Public • Published

@pulsechain/msgboard

distribute messages across networks using Proof of Work as the gate.

setup

npm i --save @pulsechain/msgboard

usage

using viem

import * as msgboard from '@pulsechain/msgboard'
import { createPublicClient, http } from 'viem'
import { pulsechainV4 } from 'viem/chains'
// create a public client for connecting to a node
const client = createPublicClient({
  transport: http(),
  chain: pulsechainV4,
})
// create the msgboard client
const board = new msgboard.MsgBoardClient(msgboard.wrap1193(client))
// do the work for your given category and data
const work = await board.doPoW('category', 'data')
// send valid work to the network
const hash = board.addMessage(work)

using ethers

import * as msgboard from '@pulsechain/msgboard'
import { providers } from 'ethers'
import { pulsechainV4 } from 'viem/chains'
// create a public client for connecting to a node
const client = new providers.JsonRpcProvider('https://my-msgboard-rpc.io')
// create the msgboard client
const board = new msgboard.MsgBoardClient(client)
// do the work for your given category and data
const work = await board.doPoW('category', 'data')
// send valid work to the network
const hash = board.addMessage(work)

understanding difficulty

difficulty can be computed by passing an encoded hex string to the getDifficulty method

board.getDifficulty('0x') // 167_772n

or by looking at the the difficulty utility found in @pulsechain/msgboard/utils

((2n ** 24n + BigInt(dataLen) * 10_000n) * workMultiplier) / workDivisor

The length of data is measured using bytes instead of hex characters. Each byte adds 10_000 increase in difficulty with the default settings. This is anticipated to encourage efficient message packing strategies while not completely out running the difficulty needed to send on the network.

blocking

because javascript blocks during proof of work checks, putting the work under a process separate from your UI render is worth consideration.

future features

  • [ ] update block by event rather than timeout

Package Sidebar

Install

npm i @pulsechain/msgboard

Weekly Downloads

40

Version

0.0.28

License

MIT

Unpacked Size

43.1 kB

Total Files

18

Last publish

Collaborators

  • 3commascapital
  • cardmagic