@asentum/sdk
v0.1.0
Published
TypeScript SDK for building on Asentum. Chain reads, wallet management, contract deployment and interaction. Works in Node.js and browsers.
Downloads
161
Maintainers
Readme
@asentum/sdk
TypeScript SDK for building on Asentum. Three classes, one import, works in Node.js and browsers.
npm install @asentum/sdkQuick start
import { AsentumClient, AsentumWallet } from '@asentum/sdk';
const client = new AsentumClient('https://testnet.asentum.com');
const wallet = AsentumWallet.create(client);
// Fund from the testnet faucet
await wallet.requestFaucet();
// Check balance
const balance = await wallet.getBalance();
console.log(balance); // 100000000000000000000n (100 ASE)
// Send ASE
const tx = await wallet.sendTransfer({
to: '0x1111111111111111111111111111111111111111',
amount: '10',
});
const receipt = await tx.wait();
console.log('confirmed in block', receipt.blockNumber);Deploy and interact with a contract
// Deploy
const contract = await wallet.deploy(`
function init() {
storage.set('greeting', 'hello world');
emit('Init', { sender: msg.sender });
}
function getGreeting() {
return storage.get('greeting');
}
function setGreeting(value) {
storage.set('greeting', value);
emit('Updated', { value });
}
`);
console.log('contract:', contract.address);
// Initialize
const initTx = await contract.send('init');
await initTx.wait();
// Read (free, no tx)
const greeting = await contract.view('getGreeting');
console.log(greeting); // "hello world"
// Write (sends a tx)
const setTx = await contract.send('setGreeting', ['gm asentum']);
await setTx.wait();
console.log(await contract.view('getGreeting')); // "gm asentum"API
AsentumClient
Read-only interface to the chain. No keys, no signing: just reads.
const client = new AsentumClient('https://testnet.asentum.com');
await client.getBlockNumber(); // number
await client.getChainId(); // bigint
await client.getBlock(42); // Block | null
await client.getBalance('0x...'); // { address, balance, nonce }
await client.getNonce('0x...'); // bigint
await client.getReceipt('0xabc...'); // Receipt | null
await client.getCode('0x...'); // hex string
await client.getContractSource('0x...'); // JS source string | null
await client.viewCall('0x...', 'name'); // ViewCallResult
await client.getValidators(); // { count, validators[] }
await client.getMetadata(); // EIP-3085 metadata
await client.isHealthy(); // boolean
await client.faucet('0x...'); // TxResult (testnet only)AsentumWallet
A client + Dilithium3 keypair. Can sign and submit transactions.
// Create random
const wallet = AsentumWallet.create(client);
// From seed (deterministic)
const wallet2 = AsentumWallet.fromSeed(client, seed32bytes);
// From exported keys
const wallet3 = AsentumWallet.fromSecretKey(client, '0xsk...', '0xpk...');
wallet.address; // '0x...' checksummed
wallet.secretKeyHex; // for backup
wallet.publicKeyHex;
await wallet.getBalance(); // bigint (wei)
await wallet.getNonce(); // bigint
await wallet.requestFaucet(); // TxResult
// Send transfer
const tx = await wallet.sendTransfer({ to: '0x...', amount: '1.5' });
const receipt = await tx.wait();
// Deploy contract
const contract = await wallet.deploy('function init() { ... }');
// Call contract (write)
const tx2 = await wallet.sendCall({
to: '0x...',
method: 'transfer',
args: ['0xbob...', '100'],
});AsentumContract
A deployed contract with view + send helpers.
// From a deploy
const contract = await wallet.deploy(source);
// Or wrap an existing address
import { AsentumContract } from '@asentum/sdk';
const contract = new AsentumContract(client, '0xcontract...');
// Read (free)
const result = await contract.view('balanceOf', ['0x...']);
// Read with full result (includes gas + events)
const full = await contract.viewFull('balanceOf', ['0x...']);
// Write (needs wallet)
const tx = await contract.send('transfer', ['0x...', '100']);
await tx.wait();
// Attach a wallet for future send() calls
const signed = contract.connect(wallet);
await signed.send('transfer', ['0x...', '50']);
// Get source code
const source = await contract.getSource();
// Wait for deploy confirmation
await contract.waitForDeploy();Helpers
import { parseAse, formatAse } from '@asentum/sdk';
parseAse('1'); // 1000000000000000000n (1 ASE in wei)
parseAse('0.5'); // 500000000000000000n
parseAse(100n); // 100n (already wei)
formatAse(1500000000000000000n); // "1.5"
formatAse('1000000000000000000'); // "1"How it works
The SDK wraps the node's HTTP RPC endpoints:
| SDK method | RPC endpoint |
|------------|-------------|
| getBlock(n) | GET /block/{n} |
| getBalance(addr) | GET /balance/{addr} |
| viewCall(addr, method, args) | POST /view |
| sendTransfer/sendCall/deploy | POST /tx (signed SSZ bytes) |
| getCode(addr) | POST / eth_getCode (JSON-RPC) |
| faucet(addr) | POST /dev/faucet |
Transactions are built via SSZ schemas from @asentum/types, hashed
with BLAKE3, signed with Dilithium3 from @asentum/crypto, and
submitted as hex-encoded wire bytes. The entire signing pipeline runs
locally: private keys never leave your process.
Requirements
- Node.js 22+ or any modern browser with
fetchandcrypto.getRandomValues - An Asentum RPC endpoint (the public testnet is at
https://testnet.asentum.com)
License
Apache-2.0
