A type-safe JavaScript/TypeScript client for interacting with a Mintlayer node via RPC.
npm install mintlayer-rpc-clientor
yarn add mintlayer-rpc-clientimport { MintlayerRpcClient } from 'mintlayer-rpc-client';
// Create a client
const client = new MintlayerRpcClient({
url: 'http://127.0.0.1:8000',
auth: {
username: 'user',
password: 'password'
}
});
// Usage examples
async function example() {
try {
// Get wallet info
const walletInfo = await client.walletInfo();
console.log('Wallet info:', walletInfo);
// Create a new account
const newAccount = await client.accountCreate({ name: 'My Account' });
console.log('New account:', newAccount);
// Generate a new address
const newAddress = await client.addressNew({ account: 0 });
console.log('New address:', newAddress);
// Check balance
const balance = await client.accountBalance({
account: 0,
utxo_states: ['Confirmed'],
with_locked: 'Unlocked'
});
console.log('Balance:', balance);
// Send coins
const txResult = await client.addressSend({
account: 0,
address: 'ml1qt72v5anu3gd04vn7r8djv0hfjz9vq9x9w3arjr4gy703mmg9zvfq8gmc5r',
amount: { decimal: '1.0' },
options: { in_top_x_mb: 5 }
});
console.log('Transaction sent:', txResult);
} catch (error) {
console.error('Error:', error);
}
}
example();The client provides type-safe methods for all Mintlayer RPC endpoints. Each method corresponds to an RPC method in the Mintlayer node.
walletCreate(params)- Create a new walletwalletOpen(params)- Open an existing walletwalletClose()- Close the currently open wallet- `walletInfo()