RPC Client API Reference¶
The DilithiaClient provides a complete interface for interacting with Dilithia blockchain nodes over JSON-RPC, REST, and WebSocket. Every language SDK exposes the same logical surface.
Configuration¶
Creating a Client¶
import { DilithiaClient, createClient } from "@dilithia/sdk";
// Direct construction
const client = new DilithiaClient({
rpcUrl: "https://rpc.dilithia.network/rpc",
timeoutMs: 15_000,
jwt: "my-bearer-token",
});
// Factory function
const client2 = createClient({ rpcUrl: "https://rpc.dilithia.network/rpc" });
use dilithia_sdk::{DilithiaClient, DilithiaClientConfig};
// Simple construction
let client = DilithiaClient::new("https://rpc.dilithia.network/rpc", None)?;
// Full configuration
let client = DilithiaClient::from_config(DilithiaClientConfig {
rpc_url: "https://rpc.dilithia.network/rpc".to_string(),
jwt: Some("my-bearer-token".to_string()),
timeout_ms: Some(15_000),
..DilithiaClientConfig::default()
})?;
See DilithiaClientConfig for all available configuration options.
URL Derivation¶
The client automatically derives related URLs from the rpcUrl:
baseUrl-- Strips/rpcsuffix fromrpcUrl(e.g.https://rpc.dilithia.network/rpcbecomeshttps://rpc.dilithia.network). Override withchainBaseUrl.wsUrl-- ConvertsbaseUrlto WebSocket protocol (e.g.https://becomeswss://). Override withwsUrl.
Authentication¶
If a jwt is configured, all requests include an Authorization: Bearer <token> header. Additional headers can be set via the headers configuration.
const headers = client.buildAuthHeaders({ "x-custom": "value" });
// { Authorization: "Bearer ...", ...configuredHeaders, "x-custom": "value" }
Balance, Nonce, and Account Queries¶
getBalance¶
Fetch the balance of an address.
Returns: A typed Balance object containing account balance fields.
getNonce¶
Fetch the current nonce (transaction count) of an address.
Returns: A typed Nonce object.
getReceipt¶
Fetch a transaction receipt by hash.
Returns: A typed Receipt object with transaction execution details.
getAddressSummary¶
Get a comprehensive summary of an address via JSON-RPC (qsc_addressSummary).
Gas and Fee Estimation¶
getGasEstimate¶
Get the current gas estimate via JSON-RPC (qsc_gasEstimate).
getBaseFee¶
Get the current base fee via JSON-RPC (qsc_baseFee).
Chain State Queries (Python)¶
The Python client includes additional chain state query methods:
| Method | RPC Method | Description |
|---|---|---|
get_head() |
qsc_head |
Current chain head |
get_chain() |
qsc_chain |
Chain metadata |
get_state_root() |
qsc_stateRoot |
Current state root hash |
get_tps() |
qsc_tps |
Current transactions per second |
get_block(height) |
qsc_getBlock |
Block at a specific height |
get_blocks(from, to) |
qsc_getBlocks |
Range of blocks |
get_tx_block(hash) |
qsc_getTxBlock |
Block containing a transaction |
get_internal_txs(hash) |
qsc_internalTxs |
Internal transactions for a tx |
get_address_txs(addr) |
qsc_getAddressTxs |
Transactions for an address |
search_hash(hash) |
qsc_search |
Search by hash |
JSON-RPC¶
jsonRpc / rawRpc¶
Send an arbitrary JSON-RPC request.
buildJsonRpcRequest¶
Build a JSON-RPC request object without sending it.
Batch Requests (Python)¶
The Python client supports JSON-RPC batch requests:
# Custom batch
results = client.json_rpc_batch([
("qsc_head", {}),
("qsc_gasEstimate", {}),
])
# Pre-built batches
overview = client.json_rpc_batch(client.build_network_overview_batch())
tx_details = client.json_rpc_batch(client.build_transaction_details_batch("0xabc..."))
addr_details = client.json_rpc_batch(client.build_address_details_batch("dili1abc..."))
REST Access¶
rawGet / rawPost¶
Send raw HTTP requests through the client (inheriting auth headers and timeout).
WebSocket¶
getWsConnectionInfo¶
Get WebSocket connection details including URL and authentication headers.
buildWsRequest¶
Build a JSON-RPC request suitable for sending over WebSocket.
Contract Deployment¶
Methods for deploying and upgrading WASM smart contracts. The workflow is: read the WASM file, hash the bytecode, build a canonical payload for signing, sign it, assemble the full DeployPayload, and send the deploy (or upgrade) request.
readWasmFileHex¶
Read a .wasm file from disk and return its contents as a hex-encoded string. This is a standalone utility function, not a method on the client.
| Parameter | Type | Description |
|---|---|---|
filePath |
string |
Path to the .wasm binary file |
Returns: string -- hex-encoded bytes of the WASM file.
buildDeployCanonicalPayload¶
Build the canonical payload for a deploy or upgrade request. Keys are sorted alphabetically for deterministic signing. The payload is signed before being included in the DeployPayload.
| Parameter | Type | Description |
|---|---|---|
from |
string |
Deployer address |
name |
string |
Contract name |
bytecodeHash |
string |
Hash of the bytecode hex (Rust hashes internally from raw hex) |
nonce |
uint64 |
Current account nonce |
chainId |
string |
Target chain identifier |
Returns: A sorted dictionary/map with keys bytecode_hash, chain_id, from, name, nonce.
deployContractRequest / deploy_contract¶
Build or send the HTTP request for deploying a new contract. TypeScript and Rust return a request descriptor; Python and Go send the request directly.
| Parameter | Type | Description |
|---|---|---|
payload |
DeployPayload |
The fully assembled deploy payload including signature |
Returns: Request descriptor (TypeScript/Rust) or the response from the deploy endpoint (Python).
upgradeContractRequest / upgrade_contract¶
Build or send the HTTP request for upgrading an existing contract. Same interface as deploy but targets the /upgrade endpoint.
| Parameter | Type | Description |
|---|---|---|
payload |
DeployPayload |
The fully assembled deploy payload including signature |
Returns: Request descriptor (TypeScript/Rust) or the response from the upgrade endpoint (Python).
queryContractAbi¶
Query a contract's ABI definition via JSON-RPC (qsc_getAbi).
| Parameter | Type | Description |
|---|---|---|
contract |
string |
Contract name or address |
Returns: The contract's ABI definition (Python sends and returns the result; others return a request to send).
Contract Interaction¶
queryContract¶
Query a smart contract's read-only method (no transaction, no gas).
buildContractCall¶
Build a contract call payload for submission.
simulate¶
Simulate a call without committing it to the chain.
sendCall¶
Submit a call to the chain.
sendSignedCall¶
Sign a canonical call payload and submit it. Requires a signer object.
The signer must implement signCanonicalPayload(payloadJson: string) (TypeScript) or sign_canonical_payload(payload_json: str) (Python), returning a dictionary with signature fields.
waitForReceipt¶
Poll for a transaction receipt until it becomes available.
| Parameter | Type | Default | Description |
|---|---|---|---|
txHash |
string |
-- | Transaction hash to poll for |
maxAttempts |
int |
12 |
Maximum number of polling attempts |
delayMs |
int |
1000 |
Delay between attempts (milliseconds) |
Name Service¶
resolveName¶
Resolve a .dili name to an address.
reverseResolveName¶
Reverse-resolve an address to its registered .dili name.
registerName¶
Register a .dili name. Cost depends on name length and is burned on-chain.
| Parameter | Type | Description |
|---|---|---|
name |
string |
The name to register (without .dili suffix) |
Returns: A NameRegistration receipt containing the registered name, expiry block, and transaction hash.
renewName¶
Renew an existing .dili name registration before it expires.
| Parameter | Type | Description |
|---|---|---|
name |
string |
The name to renew (without .dili suffix) |
durationDays |
int |
Number of days to extend the registration |
Returns: A NameRenewal receipt containing the new expiry block and transaction hash.
transferName¶
Transfer ownership of a .dili name to another address.
| Parameter | Type | Description |
|---|---|---|
name |
string |
The name to transfer |
newOwner |
string |
Destination address for the transfer |
Returns: A NameTransfer receipt containing the transaction hash and new owner address.
setNameTarget¶
Set the default resolution target address for a .dili name.
| Parameter | Type | Description |
|---|---|---|
name |
string |
The name to update |
target |
string |
The address that this name should resolve to |
Returns: A SubmitResult with the transaction hash.
setNameRecord¶
Set an arbitrary key-value record on a .dili name (e.g., avatar URL, social handle, content hash).
| Parameter | Type | Description |
|---|---|---|
name |
string |
The name to update |
key |
string |
Record key (e.g., avatar, url, github) |
value |
string |
Record value |
Returns: A SubmitResult with the transaction hash.
releaseName¶
Release a .dili name, removing it from your ownership and making it available for registration by others.
| Parameter | Type | Description |
|---|---|---|
name |
string |
The name to release |
Returns: A SubmitResult with the transaction hash.
isNameAvailable¶
Check whether a .dili name is available for registration.
| Parameter | Type | Description |
|---|---|---|
name |
string |
The name to check (without .dili suffix) |
Returns: boolean -- true if the name is not currently registered.
lookupName¶
Look up the full name record for a .dili name, including owner, target, expiry, and all custom records.
| Parameter | Type | Description |
|---|---|---|
name |
string |
The name to look up (without .dili suffix) |
Returns: A FullNameRecord containing owner, target, expiryBlock, and a map of custom records.
getNameRecords¶
Fetch all custom key-value records associated with a .dili name.
| Parameter | Type | Description |
|---|---|---|
name |
string |
The name to query (without .dili suffix) |
Returns: A dictionary/map of all custom records set on the name.
getNamesByOwner¶
Get all .dili names owned by an address.
| Parameter | Type | Description |
|---|---|---|
address |
string |
The owner address to query |
Returns: A list of name strings owned by the address.
getRegistrationCost¶
Query the registration cost for a name before registering. Cost varies by name length -- shorter names are more expensive.
// Check cost, availability, then register
const cost = await client.getRegistrationCost("alice");
console.log(`Registration costs ${cost.amount} DILI`);
const available = await client.isNameAvailable("alice");
if (available) {
const result = await client.registerName("alice");
console.log(`Registered! TX: ${result.txHash}`);
}
// Check cost, availability, then register
cost, err := client.GetRegistrationCost(ctx, "alice")
fmt.Printf("Registration costs %s DILI\n", cost.Amount)
available, err := client.IsNameAvailable(ctx, "alice")
if available {
result, err := client.RegisterName(ctx, "alice")
fmt.Printf("Registered! TX: %s\n", result.TxHash)
}
// Check cost, availability, then register
RegistrationCost cost = client.names().getRegistrationCost("alice").get();
System.out.printf("Registration costs %s DILI%n", cost.amount());
boolean available = client.names().isNameAvailable("alice").get();
if (available) {
var result = client.names().registerName("alice").send(signer);
System.out.printf("Registered! TX: %s%n", result.txHash());
}
// Check cost, availability, then register
RegistrationCost cost = await client.GetRegistrationCostAsync("alice");
Console.WriteLine($"Registration costs {cost.Amount} DILI");
bool available = await client.IsNameAvailableAsync("alice");
if (available)
{
var result = await client.RegisterNameAsync("alice");
Console.WriteLine($"Registered! TX: {result.TxHash}");
}
| Parameter | Type | Description |
|---|---|---|
name |
string |
The name to query cost for (without .dili suffix) |
Returns: A RegistrationCost object containing amount (in DILI tokens) and durationDays.
Credentials¶
Methods for managing verifiable credentials on-chain. Credentials use a schema-based model: issuers define schemas, issue credentials as commitments, and holders can produce selective disclosure proofs that verifiers check on-chain.
registerSchema¶
Register a credential schema with typed attributes. Schemas define the structure of credentials that can be issued against them.
const result = await client.registerSchema({
name: "KYCLevel2",
attributes: [
{ name: "full_name", type: "string" },
{ name: "date_of_birth", type: "date" },
{ name: "country_code", type: "string" },
{ name: "verification_level", type: "uint8" },
],
});
// result.schemaHash -- the on-chain identifier for this schema
result = client.register_schema(
name="KYCLevel2",
attributes=[
{"name": "full_name", "type": "string"},
{"name": "date_of_birth", "type": "date"},
{"name": "country_code", "type": "string"},
{"name": "verification_level", "type": "uint8"},
],
)
# result.schema_hash -- the on-chain identifier for this schema
let request = client.register_schema_request(SchemaDefinition {
name: "KYCLevel2".to_string(),
attributes: vec![
SchemaAttribute::new("full_name", AttributeType::String),
SchemaAttribute::new("date_of_birth", AttributeType::Date),
SchemaAttribute::new("country_code", AttributeType::String),
SchemaAttribute::new("verification_level", AttributeType::Uint8),
],
});
result, err := client.RegisterSchema(ctx, &sdk.SchemaDefinition{
Name: "KYCLevel2",
Attributes: []sdk.SchemaAttribute{
{Name: "full_name", Type: sdk.AttrString},
{Name: "date_of_birth", Type: sdk.AttrDate},
{Name: "country_code", Type: sdk.AttrString},
{Name: "verification_level", Type: sdk.AttrUint8},
},
})
// result.SchemaHash -- the on-chain identifier for this schema
var result = client.credentials().registerSchema(SchemaDefinition.builder()
.name("KYCLevel2")
.attribute("full_name", AttributeType.STRING)
.attribute("date_of_birth", AttributeType.DATE)
.attribute("country_code", AttributeType.STRING)
.attribute("verification_level", AttributeType.UINT8)
.build()
).send(signer);
// result.schemaHash() -- the on-chain identifier for this schema
var result = await client.RegisterSchemaAsync(new SchemaDefinition
{
Name = "KYCLevel2",
Attributes = new[]
{
new SchemaAttribute("full_name", AttributeType.String),
new SchemaAttribute("date_of_birth", AttributeType.Date),
new SchemaAttribute("country_code", AttributeType.String),
new SchemaAttribute("verification_level", AttributeType.Uint8),
},
});
// result.SchemaHash -- the on-chain identifier for this schema
| Parameter | Type | Description |
|---|---|---|
name |
string |
Human-readable schema name |
attributes |
SchemaAttribute[] |
List of attribute definitions with name and type |
Returns: A SchemaRegistration containing the schemaHash identifier and transaction hash.
issueCredential¶
Issue a credential to a holder address. The credential is stored as a commitment hash on-chain, preserving holder privacy.
| Parameter | Type | Description |
|---|---|---|
schemaHash |
string |
Hash of the schema this credential conforms to |
holder |
string |
Address of the credential holder |
commitment |
string |
Commitment hash of the credential attributes |
Returns: A CredentialIssuance containing the credential identifier and transaction hash.
revokeCredential¶
Revoke a credential by commitment hash. Only callable by the original issuer.
| Parameter | Type | Description |
|---|---|---|
commitment |
string |
Commitment hash of the credential to revoke |
Returns: A SubmitResult with the transaction hash.
verifyCredential¶
Verify a selective disclosure proof against the credential contract. The proof reveals only the attributes the holder chose to disclose.
| Parameter | Type | Description |
|---|---|---|
commitment |
string |
Commitment hash of the credential |
proof |
string |
Selective disclosure proof generated by the holder |
disclosedAttributes |
string[] |
List of attribute names included in the proof |
Returns: boolean -- true if the proof is valid against the on-chain commitment.
getCredential¶
Fetch a credential by commitment hash, including its current status.
| Parameter | Type | Description |
|---|---|---|
commitment |
string |
Commitment hash of the credential |
Returns: A Credential object containing issuer, holder, schemaHash, status (active or revoked), and issuedAtBlock.
getSchema¶
Fetch a credential schema by hash.
| Parameter | Type | Description |
|---|---|---|
schemaHash |
string |
Hash of the schema to fetch |
Returns: A CredentialSchema containing name, attributes (list of name/type pairs), issuer, and registeredAtBlock.
listCredentialsByHolder¶
List all credentials issued to a holder address.
| Parameter | Type | Description |
|---|---|---|
holder |
string |
Address of the credential holder |
Returns: A list of Credential objects held by the address.
listCredentialsByIssuer¶
List all credentials issued by an address.
| Parameter | Type | Description |
|---|---|---|
issuer |
string |
Address of the credential issuer |
Returns: A list of Credential objects issued by the address.
Shielded Pool¶
Methods for interacting with the shielded pool, which provides privacy-preserving token transfers using zero-knowledge proofs. Deposits move tokens from a public balance into the shielded pool; withdrawals extract them back. The pool maintains a Merkle tree of commitments and a set of spent nullifiers.
shieldedDeposit¶
Deposit tokens into the shielded pool.
| Parameter | Type | Description |
|---|---|---|
commitment |
string |
Pedersen commitment for the deposited value |
value |
uint64 |
Amount of tokens to deposit into the shielded pool |
proofHex |
string |
Hex-encoded zero-knowledge proof of valid commitment |
Returns: A SubmitResult with the transaction hash.
shieldedWithdraw¶
Withdraw tokens from the shielded pool back to a public address.
| Parameter | Type | Description |
|---|---|---|
nullifier |
string |
Nullifier hash to prevent double-spending |
recipient |
string |
Public address to receive the withdrawn tokens |
value |
uint64 |
Amount of tokens to withdraw |
proofHex |
string |
Hex-encoded zero-knowledge proof of valid withdrawal |
Returns: A SubmitResult with the transaction hash.
getCommitmentRoot¶
Get the current Merkle root of the shielded pool commitment tree.
Returns: string -- the current Merkle root hash of the shielded pool commitment tree.
isNullifierSpent¶
Check whether a nullifier has already been spent in the shielded pool.
| Parameter | Type | Description |
|---|---|---|
nullifier |
string |
Nullifier hash to check |
Returns: boolean -- true if the nullifier has already been used in a withdrawal.
Multisig¶
Methods for creating and managing multisignature wallets. Multisig wallets require a configurable threshold of signer approvals before a transaction can be executed. Common use cases include treasury management and DAO governance.
createMultisig¶
Create a new multisig wallet with a set of signers and an approval threshold.
| Parameter | Type | Description |
|---|---|---|
name |
string |
Human-readable name for the multisig wallet |
signers |
string[] |
List of signer addresses |
threshold |
uint32 |
Number of approvals required to execute a transaction |
Returns: A MultisigCreation containing the walletAddress and transaction hash.
proposeTx¶
Propose a new transaction from a multisig wallet. The proposer must be one of the signers.
| Parameter | Type | Description |
|---|---|---|
wallet |
string |
Multisig wallet address |
to |
string |
Destination address for the proposed transfer |
value |
uint64 |
Amount of tokens to transfer |
data |
string |
Hex-encoded call data (use "0x" for simple transfers) |
Returns: A MultisigProposal containing the txId and transaction hash.
approveMultisigTx¶
Approve a pending multisig transaction. The caller must be one of the wallet signers.
| Parameter | Type | Description |
|---|---|---|
wallet |
string |
Multisig wallet address |
txId |
uint64 |
Multisig-internal transaction ID |
Returns: A SubmitResult with the transaction hash.
executeMultisigTx¶
Execute a multisig transaction that has reached the required approval threshold.
| Parameter | Type | Description |
|---|---|---|
wallet |
string |
Multisig wallet address |
txId |
uint64 |
Multisig-internal transaction ID |
Returns: A SubmitResult with the transaction hash of the executed underlying transaction.
revokeMultisigApproval¶
Revoke a previously given approval on a pending multisig transaction.
| Parameter | Type | Description |
|---|---|---|
wallet |
string |
Multisig wallet address |
txId |
uint64 |
Multisig-internal transaction ID |
Returns: A SubmitResult with the transaction hash.
addMultisigSigner¶
Add a new signer to a multisig wallet. This operation itself requires threshold approval.
| Parameter | Type | Description |
|---|---|---|
wallet |
string |
Multisig wallet address |
signer |
string |
Address of the new signer to add |
Returns: A SubmitResult with the transaction hash.
removeMultisigSigner¶
Remove a signer from a multisig wallet. This operation itself requires threshold approval. The threshold must remain achievable with the remaining signers.
| Parameter | Type | Description |
|---|---|---|
wallet |
string |
Multisig wallet address |
signer |
string |
Address of the signer to remove |
Returns: A SubmitResult with the transaction hash.
getMultisigWallet¶
Fetch the configuration and state of a multisig wallet.
| Parameter | Type | Description |
|---|---|---|
wallet |
string |
Multisig wallet address |
Returns: A MultisigWallet containing name, signers (list of addresses), threshold, balance, and pendingTxCount.
getMultisigTx¶
Fetch the details of a specific multisig transaction by ID.
| Parameter | Type | Description |
|---|---|---|
wallet |
string |
Multisig wallet address |
txId |
uint64 |
Multisig-internal transaction ID |
Returns: A MultisigTx containing to, value, data, approvals (list of signer addresses), executed (boolean), and proposedAtBlock.
listMultisigPendingTxs¶
List all pending (not yet executed) transactions for a multisig wallet.
| Parameter | Type | Description |
|---|---|---|
wallet |
string |
Multisig wallet address |
Returns: A list of MultisigTx objects that have not yet been executed.
Gas Sponsor Connector¶
The DilithiaGasSponsorConnector simplifies working with gas sponsor contracts for meta-transactions.
Creating a Sponsor Connector¶
Sponsor Methods¶
| Method | Description |
|---|---|
buildAcceptQuery(user, contract, method) |
Check if the sponsor will accept a call |
buildRemainingQuotaQuery(user) |
Query remaining gas quota for a user |
buildMaxGasPerUserQuery() |
Query the maximum gas per user |
buildFundCall(amount) |
Build a call to fund the sponsor contract |
applyPaymaster(call) |
Attach the paymaster to a call |
sendSponsoredCall(call, signer) |
Sign and submit a sponsored call |
Messaging Connector¶
The DilithiaMessagingConnector provides cross-chain messaging functionality.
Creating a Messaging Connector¶
Messaging Methods¶
| Method | Description |
|---|---|
buildSendMessageCall(destChain, payload) |
Build an outbound cross-chain message call |
buildReceiveMessageCall(sourceChain, sourceContract, payload) |
Build an inbound message call |
sendMessage(destChain, payload, signer) |
Sign and send a cross-chain message |
queryOutbox() |
Query the messaging outbox |
queryInbox() |
Query the messaging inbox |