Skip to content
Polkadot-API

Statement SDK

The Statement Store primitive is an off-chain data store for signed messages (known as statements) accessible via RPC.

Getting Started

Install the Statement SDK using your package manager:

pnpm i @polkadot-api/sdk-statement

The function createStatementSdk takes a simple request-response function, which is expected to implement the Statement JSON-RPC API.

The actual interface of the function is

type RequestFn = (method: string, params: Array<any>) => Promise<any>

The property _request of a client can be used for this matter.

import {  } from "polkadot-api"
import {  } from "polkadot-api/ws"
 
const  = (
  ("wss://paseo-people-next-rpc.polkadot.io"),
)
 
import {  } from "@polkadot-api/sdk-statement"
 
const  = (.) 

Get Statements

Get Complete Store (dump)

The function dump will get all statements from the provider's store. Note that this endpoint might be rate-limited in some cases.

// all currently available statements of that node.
const  = await .()

Get Filtered Statements (getStatements)

This function will query for filtered statements by topic and/or dest key (find meaning in Statement Store docs.

Parameters

  • dest: SizedHex<32> for specific dest key. null for no dest key. undefined to disable filtering by dest
  • topics: Array of up to 4 topics to filter by.
import {  } from "@polkadot-api/sdk-statement"
 
// statements with specific topics and specific decryptionkey.
const  = await .({
  : [("pop"), ("chat"), ("v1")],
  : "0xf0673d30606ee26672707e4fd2bc8b58d3becb7aba2d5f60add64abb5fea4710",
})

Submit Statements

Create Statement Signer

In order to sign a Statement, we need to create a signer. This can be done with the helper getStatementSigner, taking:

  • publicKey: Pubkey of the signer
  • type: ed25519, sr25519, ecdsa signature type.
  • signFn: (payload: Uint8Array) => Uint8Array | Promise<Uint8Array> Cryptographic signing function.

As one can notice, this is very similar to the PolkadotSigner interface. Check those docs to learn more!

import {  } from "@polkadot-api/sdk-statement"
import {  } from "@noble/curves/ed25519.js"
 
const  = new () // get your key
 
const  = (
  .(),
  "ed25519",
  () => .(, ),
)

Create Statement

In order to create a statement, it is as simple as creating an UnsignedStatement object.

import {  } from "polkadot-api"
import type {  } from "@polkadot-api/sdk-statement"
 
const :  = {
  : .("0xDEADBEEF"),
  : 1,
}

Submit Statement

Once we have the signer and the statement, we can go to sign and submit it to the store!

const  = (
  .(),
  "ed25519",
  () => .(, ),
)
 
const :  = {
  : .("0xDEADBEEF"),
  : 1,
}
 
const  = await .()
 
await .()