1.0.0 • Published 8 months ago

@radiustechsystems/sdk v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Radius TypeScript SDK

A TypeScript client library for interacting with Radius, providing a simple and type-safe way to interact with the Radius platform.

Features

  • Account management and transaction signing
  • Smart contract deployment and interaction
  • Optional request logging and interceptors
  • EVM compatibility with high performance
  • Type-safe contract interactions

Requirements

  • Node.js >= 20.12.2
  • npm, yarn, or pnpm

Installation

# Using npm
npm install @radiustechsystems/sdk

# Using pnpm
pnpm add @radiustechsystems/sdk

# Using yarn
yarn add @radiustechsystems/sdk

Quickstart Examples

Connect to Radius and Create an Account

import { NewClient, NewAccount, withPrivateKey } from '@radiustechsystems/sdk';

// Connect to Radius
const client = await NewClient('https://your-radius-endpoint');

// Create an account using a private key
const account = await NewAccount(withPrivateKey('your-private-key', client));

Transfer Value Between Accounts

import { AddressFromHex } from '@radiustechsystems/sdk';

// Send 100 tokens to another account
const recipient = AddressFromHex('0x...');
const amount = BigInt(100);
const receipt = await account.send(client, recipient, amount);

console.log('Transaction hash:', receipt.txHash.hex());

Deploy a Smart Contract

import { ABIFromJSON, BytecodeFromHex } from '@radiustechsystems/sdk';

// Parse ABI and bytecode
const abi = new ABIFromJSON(`[{"inputs":[],"name":"get","outputs":[{"type":"uint256"}],"type":"function"},{"inputs":[{"type":"uint256"}],"name":"set","type":"function"}]`);
const bytecode = BytecodeFromHex('608060405234801561001057600080fd5b50610150806100...');

// Deploy the contract
const contract = await client.deployContract(account.signer, bytecode, abi);

Interact with a Smart Contract

import { NewContract, AddressFromHex, ABIFromJSON } from '@radiustechsystems/sdk';

// Reference an existing contract
const address = AddressFromHex('0x...');
const abi = new ABIFromJSON(`[{"inputs":[],"name":"get","outputs":[{"type":"uint256"}],"type":"function"},{"inputs":[{"type":"uint256"}],"name":"set","type":"function"}]`);
const contract = NewContract(address, abi);

// Write to the contract
const value = BigInt(42);
const receipt = await contract.execute(client, account.signer, 'set', value);

// Read from the contract
const result = await contract.call(client, 'get');
console.log('Stored value:', result[0]);

Advanced Features

Custom Transaction Signing

import { NewClefSigner, NewAccount, withSigner, AddressFromHex } from '@radiustechsystems/sdk';

// Use an external signer (e.g., Clef)
const address = AddressFromHex('0x...');
const clefSigner = NewClefSigner(address, client, 'http://localhost:8550');
const account = await NewAccount(withSigner(clefSigner));

// Or create a custom signer
const customSigner = new MyCustomSigner();
const customSignerAccount = NewAccount(withSigner(customSigner));

Logging and Request Interceptors

import { NewClient, withLogger, withInterceptor } from '@radiustechsystems/sdk';

const client = await NewClient('https://your-radius-endpoint',
    withLogger((message, data) => {
        console.log(message, data);
    }),
    withInterceptor(async (reqBody, response) => {
        // Process or log responses
        return response;
    })
);

Custom HTTP Client

import { NewClient, withHttpClient } from '@radiustechsystems/sdk';

const client = await NewClient('https://your-radius-endpoint',
    withHttpClient(customHttpClient)
);

Resources

Contributing

Please see the TypeScript SDK Contributing Guide for detailed information about contributing to this SDK. For repository-wide guidelines, see the General Contributing Guide.

License

This project is licensed under the MIT License.