11# Radius TypeScript SDK
22
3- A TypeScript client library for interacting with [ Radius] ( https://radiustech.xyz/ ) , providing a simple and type-safe
4- way to interact with the Radius platform .
3+ The official TypeScript client library for interacting with the [ Radius platform ] ( https://radiustech.xyz/ ) , providing
4+ a simple and idiomatic way to interact with Radius services .
55
66## Features
77
88- Account management and transaction signing
99- Smart contract deployment and interaction
1010- Optional request logging and interceptors
11- - EVM compatibility with high performance
12- - Type-safe contract interactions
11+ - EVM compatibility with high performance & low latency
1312
1413## Requirements
1514
16- - Node.js >= 20.12.2
15+ - Node.js >= 20.12
16+ - Radius JSON-RPC endpoint: https://docs.radiustech.xyz/radius-testnet-access
17+ - Ethereum private key: https://ethereum.org/en/developers/docs/accounts/#account-creation
1718
1819## Installation
1920
@@ -32,58 +33,74 @@ yarn add @radiustechsystems/sdk
3233
3334### Connect to Radius and Create an Account
3435
36+ Be sure to use your own ` RADIUS_ENDPOINT ` and ` PRIVATE_KEY ` values, as mentioned in the [ Requirements] ( #requirements ) .
37+
3538``` typescript
36- import { NewClient , NewAccount , withPrivateKey } from ' @radiustechsystems/sdk' ;
39+ import { Account , Client , NewClient , NewAccount , withPrivateKey } from ' @radiustechsystems/sdk' ;
40+
41+ const RADIUS_ENDPOINT = " https://rpc.testnet.tryradi.us/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ;
42+ const PRIVATE_KEY = " fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036415f" ;
43+
44+ const client: Client = await NewClient (RADIUS_ENDPOINT );
45+ const account: Account = await NewAccount (withPrivateKey (PRIVATE_KEY , client ));
46+ ```
3747
38- // Connect to Radius
39- const client = await NewClient (' https://your-radius-endpoint' );
48+ Alternatively, using plain JavaScript and CommonJS ` require ` syntax:
4049
41- // Create an account using a private key
42- const account = await NewAccount ( withPrivateKey ( ' your-private-key ' , client ) );
50+ ``` javascript
51+ const { Account , Client , NewClient , NewAccount , withPrivateKey } = require ( ' @radiustechsystems/sdk ' );
4352```
4453
4554### Transfer Value Between Accounts
4655
56+ Here, we send 100 tokens to another account. Be sure to replace the recipient's address with one of your own.
57+
4758``` typescript
48- import { AddressFromHex } from ' @radiustechsystems/sdk' ;
59+ import { Address , AddressFromHex , Receipt } from ' @radiustechsystems/sdk' ;
4960
50- // Send 100 tokens to another account
51- const recipient = AddressFromHex (' 0x...' );
52- const amount = BigInt (100 );
53- const receipt = await account .send (client , recipient , amount );
61+ const recipient: Address = AddressFromHex (' 0x5e97870f263700f46aa00d967821199b9bc5a120' ); // Recipient's address
62+ const amount: bigint = BigInt (100 );
63+ const receipt: Receipt = await account .send (client , recipient , amount );
5464
5565console .log (' Transaction hash:' , receipt .txHash .hex ());
5666```
5767
5868### Deploy a Smart Contract
5969
70+ Here, we deploy the [ SimpleStorage.sol] ( https://github.com/radiustechsystems/sdk/tree/main/contracts/solidity )
71+ example contract included in this SDK, with the application binary interface (ABI) and bytecode that were generated
72+ using the Solidity compiler [ solcjs] ( https://docs.soliditylang.org/en/latest/installing-solidity.html#npm-node-js ) .
73+
6074``` typescript
61- import { ABIFromJSON , BytecodeFromHex } from ' @radiustechsystems/sdk' ;
75+ import { ABI , ABIFromJSON , BytecodeFromHex } from ' @radiustechsystems/sdk' ;
6276
63- // Parse ABI and bytecode
64- const abi = ABIFromJSON (` [{"inputs":[],"name":"get","outputs":[{"type":"uint256"}],"type":"function"},{"inputs":[{"type":"uint256"}],"name":"set","type":"function"}] ` );
65- const bytecode = BytecodeFromHex (' 608060405234801561001057600080fd5b50610150806100... ' );
77+ // Parse ABI and bytecode of the SimpleStorage contract
78+ const abi: ABI = ABIFromJSON (` [{"inputs":[],"name":"get","outputs":[{"type":"uint256"}],"type":"function"},{"inputs":[{"type":"uint256"}],"name":"set","type":"function"}] ` );
79+ const bytecode: Uint8Array = BytecodeFromHex (' 6080604052348015600e575f5ffd5b5060a580601a5f395ff3fe6080604052348015600e575f5ffd5b50600436106030575f3560e01c806360fe47b11460345780636d4ce63c146045575b5f5ffd5b6043603f3660046059565b5f55565b005b5f5460405190815260200160405180910390f35b5f602082840312156068575f5ffd5b503591905056fea26469706673582212207655d86666fa8aa75666db8416e0f5db680914358a57e84aa369d9250218247f64736f6c634300081c0033 ' );
6680
6781// Deploy the contract
6882const contract = await client .deployContract (account .signer , bytecode , abi );
6983```
7084
7185### Interact with a Smart Contract
7286
87+ Assuming the contract was previously deployed (which is typically the case), we can interact with it using the contract
88+ address and ABI. Be sure to replace the contract address with that of your own deployed contract.
89+
7390``` typescript
74- import { NewContract , AddressFromHex , ABIFromJSON } from ' @radiustechsystems/sdk' ;
91+ import { ABI , Address , AddressFromHex , ABIFromJSON , Contract , NewContract , Receipt } from ' @radiustechsystems/sdk' ;
7592
76- // Reference an existing contract
77- const address = AddressFromHex (' 0x... ' );
78- const abi = ABIFromJSON (` [{"inputs":[],"name":"get","outputs":[{"type":"uint256"}],"type":"function"},{"inputs":[{"type":"uint256"}],"name":"set","type":"function"}] ` );
79- const contract = NewContract (address , abi );
93+ // Reference a previously deployed contract
94+ const address: Address = AddressFromHex (' 0x5e97870f263700f46aa00d967821199b9bc5a120 ' ); // Contract address
95+ const abi: ABI = ABIFromJSON (` [{"inputs":[],"name":"get","outputs":[{"type":"uint256"}],"type":"function"},{"inputs":[{"type":"uint256"}],"name":"set","type":"function"}] ` );
96+ const contract: Contract = NewContract (address , abi );
8097
8198// Write to the contract
82- const value = BigInt (42 );
83- const receipt = await contract .execute (client , account .signer , ' set' , value );
99+ const value: bigint = BigInt (42 );
100+ const receipt: Receipt = await contract .execute (client , account .signer , ' set' , value );
84101
85102// Read from the contract
86- const result = await contract .call (client , ' get' );
103+ const result: unknown [] = await contract .call (client , ' get' );
87104console .log (' Stored value:' , result [0 ]);
88105```
89106
@@ -148,4 +165,4 @@ SDK. For repository-wide guidelines, see the [General Contributing Guide](../CON
148165
149166## License
150167
151- This project is licensed under the [ MIT License] ( ../LICENSE ) .
168+ All Radius SDKs are released under the [ MIT License] ( ../LICENSE ) .
0 commit comments