@appliedblockchain/silentdatarollup-viem
v1.1.0
Published
Viem package for Silent Data
Downloads
418
Maintainers
Readme
Silent Data Providers - Viem Transport Package
Table of Contents
Introduction
Viem custom transport for Silent Data.
Prerequisites
- Node.js (version 20 or higher)
- pnpm
- Basic knowledge of Ethereum and smart contracts
- Viem
Integration
Basic Usage
Installing Basic Usage Dependencies
pnpm add @appliedblockchain/silentdatarollup-viemBasic Usage Example
import { defineChain, createPublicClient, createWalletClient } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { sdTransport } from '@appliedblockchain/silentdatarollup-viem'
const providerConfig = {
rpcUrl: 'SILENT_DATA_ROLLUP_RPC_URL',
chainId: 'SILENT_DATA_CHAIN_ID',
privateKey: 'YOUR_PRIVATE_KEY',
}
const account = privateKeyToAccount(providerConfig.privateKey)
const transport = sdTransport(providerConfig)
const sdChain = defineChain({
id: providerConfig.chainId,
name: 'SILENT_DATA_CHAIN_NAME',
nativeCurrency: {
name: 'Ether',
symbol: 'ETH',
decimals: 18,
},
rpcUrls: {
default: {
http: [providerConfig.rpcUrl],
},
},
})
const publicClient = createPublicClient({
chain: sdChain,
transport,
})
const walletClient = createWalletClient({
chain: sdChain,
transport,
account,
})
const balance = await publicClient.getBalance({ address: account.address })
console.log('Balance:', balance)
const transactionCount = await publicClient.getTransactionCount({
address: account.address,
})
console.log('Transaction count:', transactionCount)
const recipientAddress = 'RECIPIENT_ADDRESS'
const amountInWei = BigInt('1')
const transactionHash = await walletClient.sendTransaction({
to: recipientAddress,
value: amountInWei,
})
console.log('Transaction Hash:', transactionHash)License
This project is licensed under the MIT License.
Troubleshooting
If you encounter any issues, please check the following:
- Ensure you're using the correct RPC URL for your desired network.
- Verify that your private key is correctly set.
- Ensure that your token is active on the SilentData AppChains dashboard.
