Class KleverProvider
Implements
Index
Constructors
Properties
Methods
Constructors
constructor
Creates a new KleverProvider instance
Parameters
Optionalconfig: ProviderConfigProvider configuration options Can be:
- undefined: Uses mainnet
- A network name: 'mainnet', 'testnet', 'devnet', 'local'
- A config object with network or custom URL
Returns KleverProvider
Properties
ProtectedapiClient
Protected Optionalcache
Protected Readonlydebug
Readonlynetwork
ProtectednodeClient
Methods
batch
broadcastTransaction
Broadcasts a single signed transaction to the network
Parameters
- tx: unknown
The signed transaction data
Returns Promise<IBroadcastResult>
Broadcast result with transaction hash
- tx: unknown
broadcastTransactions
Broadcasts multiple signed transactions to the network in a single batch
Parameters
- txs: unknown[]
Array of signed transaction data
Returns Promise<IBulkBroadcastResult>
Broadcast result with array of transaction hashes
- txs: unknown[]
buildTransaction
Build transaction using node endpoint Node will handle nonce fetching (if missing), fee calculation, and proto encoding
This method provides server-side transaction building where the node does the heavy lifting:
- Fetches nonce if not provided
- Calculates kAppFee and bandwidthFee
- Encodes transaction to proto format
- Returns proto transaction object and transaction hash
Parameters
- request: BuildTransactionRequest
Transaction build request with contracts and optional sender/nonce
Returns Promise<BuildTransactionResponse>
Proto transaction object and transaction hash
Example
const request = {
sender: 'klv1...',
contracts: [{
type: TXType.Transfer,
parameter: { receiver: 'klv1...', amount: 1000000n, kda: 'KLV' }
}]
}
const tx = await provider.buildTransaction(request)
// tx.result contains proto transaction object (ITransaction)
// tx.txHash contains the transaction hash
call
Calls a contract method (generic API call)
TODO: Implementation pending - generic contract calls not yet supported
This is a low-level method for making arbitrary contract API calls. For standard contract queries, use
queryContract()instead.Type Parameters
Parameters
- _endpoint: string
The API endpoint for the contract call
Optional_params: Record<string, unknown>The parameters for the contract call
Returns Promise<T>
The result of the contract call
- _endpoint: string
clearCache
Clear all cached data
Returns void
estimateFee
Estimates the fee for a transaction
TODO: Implementation pending - currently returns zero fees
This method will calculate the expected fees for a transaction including:
- kAppFee: Application-specific fee
- bandwidthFee: Network bandwidth cost
- gasEstimated: Estimated gas for smart contract execution
Parameters
- _tx: unknown
The transaction request to estimate fees for
Returns Promise<IFeesResponse>
The estimated fee breakdown
Example
// Future usage (not yet implemented)
const fees = await provider.estimateFee({
sender: 'klv1...',
contracts: [{
type: TXType.Transfer,
parameter: { receiver: 'klv1...', amount: 1000000n }
}]
})
console.log('Estimated kAppFee:', fees.kAppFee)
console.log('Estimated bandwidthFee:', fees.bandwidthFee)
getAccount
Retrieves account information from the blockchain
Parameters
- address: KleverAddress
The Klever address to query
Optionaloptions: { skipCache?: boolean }Additional options
Returns Promise<IAccount>
Account information including balance and assets
- address: KleverAddress
getAccountInfo
Alias for getAccount() - matches Solana web3.js naming convention
Parameters
- address: KleverAddress
Optionaloptions: { skipCache?: boolean }
Returns Promise<IAccount>
getBalance
Get balance for a specific token
Parameters
- address: KleverAddress
Klever address
- token: string = 'KLV'
Token identifier (e.g., 'KLV', 'KDA-ABC123')
Returns Promise<bigint>
Balance as bigint
- address: KleverAddress
getBlock
Get block by nonce, hash, or "latest"
Parameters
- blockHashOrNumber: BlockIdentifier
Block nonce (number), hash (string), or "latest"
Returns Promise<null | IBlockResponse>
Block information
- blockHashOrNumber: BlockIdentifier
getBlockNumber
Get the current block number (nonce) from the blockchain
Returns Promise<number>
Current block nonce
getNetwork
Get the network object
Returns Network
getNetworkName
Get the network name
Returns NetworkName
getNonce
Get the current nonce for an address Convenience method that extracts nonce from getAccount
Parameters
- address: KleverAddress
Klever address
Returns Promise<number>
Current nonce value
- address: KleverAddress
getTransaction
Retrieves transaction information by hash
Parameters
- hash: string | TransactionHash
The transaction hash (as TransactionHash branded type or string)
Returns Promise<null | ITransactionResponse>
Transaction details including receipts, or null if not found
- hash: string | TransactionHash
getTransactionReceipt
Retrieves transaction receipt(s) by hash
Receipts contain detailed information about what happened during transaction execution, including transfers, freezes, claims, and other operations.
Parameters
- hash: string | TransactionHash
The transaction hash (as TransactionHash branded type or string)
Returns Promise<null | IReceipt[]>
Array of receipts or null if transaction not found
Example
// Get receipts after transaction is mined
const receipts = await provider.getTransactionReceipt(txHash)
if (receipts) {
console.log(`Transaction has ${receipts.length} receipt(s)`)
receipts.forEach(receipt => {
console.log(`Type: ${receipt.typeString}, Asset: ${receipt.assetId}`)
})
}
// Parse receipts with type-safe parsers
import { parseReceipt } from '@klever/connect-provider'
const tx = await provider.getTransaction(txHash)
if (tx) {
const freezeData = parseReceipt.freeze(tx)
console.log(`Bucket ID: ${freezeData.bucketId}`)
}- hash: string | TransactionHash
getTransactionUrl
Get the full URL for viewing a transaction in the explorer
Parameters
- txHash: string | TransactionHash
The transaction hash (as TransactionHash branded type or string)
Returns string
The full URL to view the transaction
- txHash: string | TransactionHash
off
Unsubscribe from provider events
TODO: Implementation pending - event unsubscription not yet supported
Parameters
- _event: ProviderEvent
The event type to unsubscribe from
- _listener: (...args: unknown[]) => void
The callback function to remove
Returns void
- _event: ProviderEvent
on
Subscribe to provider events
TODO: Implementation pending - event subscription not yet supported
This method will allow subscribing to blockchain events like:
- New blocks
- Pending transactions
- Account balance changes
- Contract events
Parameters
- _event: ProviderEvent
The event type to subscribe to
- _listener: (...args: unknown[]) => void
Callback function to handle the event
Returns void
queryContract
Queries a smart contract (read-only, no gas cost)
Contract queries are free and don't require signing or broadcasting. Use this to read contract state or call view functions.
Parameters
- params: IContractQueryParams
Contract query parameters
Returns Promise<IContractQueryResult>
Query result with return data and status
Example
// Query contract balance
const result = await provider.queryContract({
scAddress: 'klv1contract...',
funcName: 'getBalance',
args: ['klv1user...']
})
if (result.error) {
console.error('Query failed:', result.error)
} else {
console.log('Return data:', result.data?.returnData)
console.log('Gas remaining:', result.data?.gasRemaining)
}- params: IContractQueryParams
requestTestKLV
Requests test KLV from faucet (testnet/devnet only)
Parameters
- address: KleverAddress
The address to send test KLV to
Optionalamount: bigintOptional amount to request (in smallest unit)
Returns Promise<IFaucetResult>
Faucet result with transaction hash and status
Example
// Request test KLV on testnet
const provider = new KleverProvider('testnet')
const result = await provider.requestTestKLV('klv1...')
console.log('Faucet TX:', result.txHash)
console.log('Status:', result.status)
// Wait for confirmation
await provider.waitForTransaction(result.txHash)
const balance = await provider.getBalance('klv1...')
console.log('New balance:', balance)- address: KleverAddress
sendRawTransaction
Sends a single raw transaction to the network
Parameters
- signedTx: unknown
Signed transaction data (hex string, JSON string, Uint8Array, or Transaction object)
Returns Promise<TransactionHash>
The transaction hash
- signedTx: unknown
sendRawTransactions
Sends multiple raw transactions to the network in a single batch
Parameters
- signedTxs: unknown[]
Array of signed transaction data (hex strings, JSON strings, Uint8Arrays, or Transaction objects)
Returns Promise<TransactionHash[]>
Array of transaction hashes
- signedTxs: unknown[]
sendTransaction
Alias for broadcastTransaction() - matches ethers.js and web3.js naming convention More commonly used in Web3 ecosystems
Parameters
- tx: unknown
Returns Promise<IBroadcastResult>
waitForTransaction
- waitForTransaction(
hash: string | TransactionHash,
confirmations?: number,
onProgress?: (
status: "pending" | "failed" | "confirming" | "timeout",
data: {
attempts: number;
confirmations?: number;
maxAttempts: number;
required?: number;
transaction?: ITransactionResponse;
},
) => void,
): Promise<null | ITransactionResponse>Waits for a transaction to be mined and confirmed
Parameters
- hash: string | TransactionHash
The transaction hash (as TransactionHash branded type or string)
Optionalconfirmations: numberNumber of confirmations to wait for (default: 1)
OptionalonProgress: (
status: "pending" | "failed" | "confirming" | "timeout",
data: {
attempts: number;
confirmations?: number;
maxAttempts: number;
required?: number;
transaction?: ITransactionResponse;
},
) => voidOptional callback for progress updates
Returns Promise<null | ITransactionResponse>
The transaction or null if not found/timeout
Example
// Basic usage
const tx = await provider.waitForTransaction(hash)
// With progress callback for UI updates
const tx = await provider.waitForTransaction(hash, 3, (status, data) => {
if (status === 'pending') {
console.log(`Attempt ${data.attempts}/${data.maxAttempts}`)
} else if (status === 'confirming') {
console.log(`Confirmations: ${data.confirmations}/${data.required}`)
}
}) - hash: string | TransactionHash
Klever blockchain provider with built-in caching and retry capabilities
Example