@appliedblockchain/silentdatarollup-ethers-provider
v1.0.1
Published
Ethers.js provider for Silent Data [Rollup]
Downloads
653
Maintainers
Readme
Silent Data [Rollup] Providers - Ethers Provider Package
Table of Contents
Introduction
Custom providers for Silent Data [Rollup], compatible with ethers.js.
Prerequisites
- Node.js (version 18 or higher)
- npm
- Basic knowledge of Ethereum and smart contracts
- Ethers.js v6
Integration
Basic Usage
Installing Basic Usage Dependencies
npm install @appliedblockchain/silentdatarollup-core @appliedblockchain/silentdatarollup-ethers-provider ethers@6
Basic Usage Example
import { NetworkName } from '@appliedblockchain/silentdatarollup-core'
import {
NetworkName,
SilentDataRollupProvider,
} from '@appliedblockchain/silentdatarollup-ethers-provider'
import { Wallet } from 'ethers'
const providerConfig = {
rpcUrl: 'SILENT_DATA_ROLLUP_RPC_URL',
network: NetworkName.TESTNET,
privateKey: 'YOUR_PRIVATE_KEY',
}
const provider = new SilentDataRollupProvider(providerConfig)
const balance = await provider.getBalance('YOUR_ADDRESS')
console.log(balance)
Usage with a Contract
Installing Usage with a Contract Dependencies
npm install @appliedblockchain/silentdatarollup-core @appliedblockchain/silentdatarollup-ethers-provider ethers@6
Usage with a Contract Example
import {
ChainId,
SilentDataRollupContract,
} from '@appliedblockchain/silentdatarollup-core'
import { SilentDataRollupProvider } from '@appliedblockchain/silentdatarollup-ethers-provider'
import { ethers } from 'ethers'
const providerConfig = {
rpcUrl: 'SILENT_DATA_ROLLUP_RPC_URL',
network: NetworkName.TESTNET,
privateKey: 'YOUR_PRIVATE_KEY',
}
const provider = new SilentDataRollupProvider(providerConfig)
const balance = await provider.getBalance('YOUR_ADDRESS')
console.log(balance)
const contractConfig = {
contractAddress: 'YOUR_CONTRACT_ADDRESS'
abi: [ /* Your contract ABI */ ],
runner: provider,
methodsToSign: ['method1', 'method2'] // Contract read calls that require signing
}
const contract = new SilentDataRollupContract(contractConfig)
// Now you can call "private" contract methods. These calls will be signed,
// and msg.sender will be available in the contract, representing the signer's address.
const privateMethodResult = await contract.method1('param1', 'param2')
console.log('Private method result:', privateMethodResult)
// You can also call methods that don't require signing.
// These calls won't include a signature, and msg.sender won't be available in the contract.
const publicMethodResult = await contract.method3('param1', 'param2')
console.log('Public method result:', publicMethodResult)
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.