distribute messages across networks using Proof of Work as the gate.
npm i --save @pulsechain/msgboard
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)
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.
because javascript blocks during proof of work checks, putting the work under a process separate from your UI render is worth consideration.
- [ ] update block by event rather than timeout