shreds NPM Module
The shreds npm module is the official TypeScript SDK for interacting with RISE Chain's Shred API. It provides type-safe methods for instant transactions, real-time subscriptions, and seamless viem integration.
Installation
npm
npm install shreds viemCore Functions
sendTransactionSync
Sends a transaction and waits for instant confirmation via shreds.
import { sendTransactionSync } from 'shreds/viem'
const hash = await sendTransactionSync(walletClient, {
to: '0x742d35Cc6634C0532925a3b844Bc9e7595f6E98d',
value: parseEther('1.0'),
data: '0x',
})
// @log: Transaction confirmed in ~4ms with hash: 0x...Parameters
client- WalletClient instance from viemrequest- Transaction request objectto- Recipient addressvalue- Amount in wei (optional)data- Contract call data (optional)gas- Gas limit (optional, estimated if not provided)gasPrice- Gas price (optional)maxFeePerGas- Max fee for EIP-1559 (optional)maxPriorityFeePerGas- Max priority fee (optional)nonce- Transaction nonce (optional)
Returns
Promise<Hash> - Transaction hash after confirmation
Example with Contract Call
import { encodeFunctionData } from 'viem'
import { sendTransactionSync } from 'shreds/viem'
const hash = await sendTransactionSync(walletClient, {
to: tokenAddress,
data: encodeFunctionData({
abi: erc20Abi,
functionName: 'transfer',
args: [recipient, parseEther('100')]
})
})watchShreds
Subscribe to real-time shred updates via WebSocket.
import { watchShreds } from 'shreds/viem'
const unwatch = watchShreds(publicClient, {
onShred: (shred) => {
console.log('New shred:', shred)
}
})
// Later: unwatch()Parameters
client- PublicClient with WebSocket transportoptions- Subscription optionsonShred- Callback function for new shredsonError- Error handler (optional)
Returns
UnwatchFn - Function to unsubscribe
Shred Object Structure
interface Shred {
blockTimestamp: bigint;
blockNumber: bigint;
shredIndex: number;
startingLogIndex: number;
transactions: ShredTransaction[];
stateChanges: ShredStateChange[];
}Chain Configuration
Pre-configured Chains
import { riseTestnet } from 'viem/chains'
// Use with viem
const client = createPublicClient({
chain: riseTestnet,
transport: http()
})Available Chains
riseTestnet- RISE testnet configuration
TypeScript Support
The module is written in TypeScript and exports all types:
import type {
Shred,
} from 'shreds/viem'
// Use in your own functions
async function myShredHandler(shred: Shred): Promise<void> {
// Type-safe shred handling
}Best Practices
- Always handle errors - Network issues can occur
- Use typed imports - Better IDE support and type safety
- Monitor gas prices - Even though confirmations are instant
- Test on testnet first - Get familiar with shred behavior
Migration from Standard viem
// Before: Standard viem
const hash = await walletClient.sendTransaction(request)
const receipt = await publicClient.waitForTransactionReceipt({ hash })
// After: With shreds
import { sendTransactionSync } from 'shreds/viem'
const receipt = await sendTransactionSync(walletClient, request)
// Already confirmed!