SDK & Client Integration¶
The sdk crate (packages/sdk) provides Rust types and an optional HTTP client for interacting with Wasichain nodes.
Installation¶
[dependencies]
sdk = { path = "../chain/packages/sdk" }
# Enable the HTTP client (pulls in reqwest + tokio)
sdk = { path = "../chain/packages/sdk", features = ["client"] }
Feature flags¶
| Feature | Dependencies | What it enables |
|---|---|---|
| (default) | none | Re-exported types only (addresses, transactions, signing, receipts) |
client |
reqwest, tokio |
ChainClient for HTTP communication with a node |
Re-exported types¶
The SDK re-exports core types so consumers do not need to depend on the types crate directly:
Address,Hash,format_hash,parse_hash,sha256,derive_contract_addressTx,SignedTxExecutionReceipt,CallTrace,EventGasSchedulegenerate_keypair,load_signing_key,sign_tx,verify_tx_signatureSubMessage,SubMessageResult,ReplyOnCodeRecord,CodeStatus,ContractRecordDEFAULT_VM_VERSION
ChainClient¶
When the client feature is enabled, ChainClient provides typed methods for all RPC endpoints:
use sdk::ChainClient;
let client = ChainClient::new("http://127.0.0.1:26657");
// Query node status
let status = client.status().await?;
println!("height: {}, epoch: {}", status.height, status.epoch);
// Check account balance and nonce
let acct = client.account("0x<ADDRESS>").await?;
// Submit a signed transaction
let tx_resp = client.submit_tx(&signed_tx).await?;
// Look up a transaction receipt
let receipt = client.get_tx(&tx_resp.tx_hash).await?;
// Query code status
let code = client.code_by_hash("0x<HASH>").await?;
// Poll until code is activated
let code = client.wait_for_code("0x<HASH>", "activated", Duration::from_secs(2)).await?;
// Query a contract
let result = client.query_contract("0x<ADDR>", msg_bytes).await?;
// Get validator set
let vset = client.validator_set().await?;
// Get block transactions
let block = client.block_txs(42).await?;
Signing transactions¶
use sdk::{generate_keypair, sign_tx, Tx};
let (signing_key, address) = generate_keypair();
let tx = Tx::Transfer { to: recipient, amount: 1000 };
let signed = sign_tx(tx, nonce, &signing_key);
Deriving contract addresses¶
Contract addresses are deterministic, derived from the creator address, code ID, and a salt: