LogoLogo
  • Introduction
  • Radius testnet access
  • Quickstart
    • Command line
    • Go
    • JavaScript
    • Postman
    • Python
    • Rust
    • TypeScript
  • How to
    • Create a Private Key
    • Get testnet ETH tokens
    • Deploy a smart contract
  • Concepts
    • Ethereum transaction types
  • Tutorials
  • Radius SDKs
  • API Reference
    • eth_blockNumber
    • eth_call
    • eth_chainId
    • eth_createAccessList
    • eth_estimateGas
    • eth_feeHistory
    • eth_gasPrice
    • eth_getBalance
    • eth_getBlock
    • eth_getBlockByHash
    • eth_getBlockByNumber
    • eth_getBlockTransactionCountByHash
    • eth_getBlockTransactionCountByNumber
    • eth_getCode
    • eth_getLogs
    • eth_getStorageAt
    • eth_getTransactionByBlockHashAndIndex
    • eth_getTransactionByBlockNumberAndIndex
    • eth_getTransactionByHash
    • eth_getTransactionCount
    • eth_getTransactionReceipt
    • eth_sendRawTransaction
    • eth_sendTransaction
    • net_version
    • web3_clientVersion
    • web3_sha3
    • web3_getTransactionCount
  • Release Notes
  • Whitepaper
  • Radius Discord
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Quickstart

JavaScript

PreviousGoNextPostman

Last updated 2 months ago

Was this helpful?

1

In your project folder, create a minimal package.jsonfile:

{
  "name": "radius-quickstart",
  "version": "1.0.0",
  "type": "commonjs",
  "dependencies": {
    "@radiustechsystems/sdk": "^1.0.0"
  }
}
2

Install the Radius TypeScript SDK:

npm i @radiustechsystems/sdk
3

Create a TypeScript file called index.js:

const {
  AddressFromHex,
  NewClient,
  NewAccount,
  withPrivateKey,
} = require('@radiustechsystems/sdk');

// Replace the following values with your own
const RADIUS_ENDPOINT = "https://rpc.testnet.tryradi.us/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const PRIVATE_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

async function main() {
  const client = await NewClient(RADIUS_ENDPOINT);
  const account = await NewAccount(withPrivateKey(PRIVATE_KEY, client));
  const recipient = AddressFromHex('0x...'); // Replace with recipient address
  const amount = BigInt(100);
  const receipt = await account.send(client, recipient, amount);

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

main().catch(console.error);
4

Compile and run the code using the following command:

node index.js
1

In your project folder, install the node-fetch package using npm:

npm i node-fetch
2

Create a JavaScript file called index.js:

import fetch from "node-fetch"

const url = "https://rpc.testnet.tryradi.us/<YOUR-RPC-ENDPOINT>"

fetch(url, {
    method: "POST",
    headers: {
        "Content-Type": "application/json",
    },
    body: JSON.stringify({
        jsonrpc: "2.0",
        method: "eth_blockNumber",
        params: [],
        id: 1,
    }),
})
    .then((response) => response.json())
    .then((data) => {
        console.log(data)
    })
    .catch((error) => {
        console.error(error)
    })
3

Run the code using the following command:

node index.js
1

In your project folder, install the axios package using npm:

npm i axios
2

Create a JavaScript file called index.js:

import axios from "axios"

const url = "https://rpc.testnet.tryradi.us/<YOUR-RPC-ENDPOINT>"

axios
  .post(url, {
    jsonrpc: "2.0",
    method: "eth_blockNumber",
    params: [],
    id: 1,
  })
  .then((response) => {
    console.log(response.data)
  })
  .catch((error) => {
    console.error(error)
  })
3

Run the code using the following command:

node index.js
1

In your project folder, install the ethers package using npm:

npm i ethers
2

Create a JavaScript file called index.js:

import { ethers } from "ethers"

const url = "https://rpc.testnet.tryradi.us/<YOUR-RPC-ENDPOINT>"
const provider = new ethers.JsonRpcProvider(url)

provider
  .getBlockNumber()
  .then((blockNumber) => {
    console.log(blockNumber)
  })
  .catch((error) => {
    console.error(error)
  })
3

Run the code using the following command:

node index.js
1

In your project folder, install the web3 package using npm:

npm i web3
2

Create a JavaScript file called index.js:

import { Web3 } from "web3"

const url = "https://rpc.testnet.tryradi.us/<YOUR-RPC-ENDPOINT>"
const provider = new Web3.providers.HttpProvider(url)
const web3 = new Web3(provider)

web3.eth
  .getBlockNumber()
  .then((blockNumber) => {
    console.log(blockNumber)
  })
  .catch((error) => {
    console.error(error)
  })
3

Run the code using the following command:

node index.js

Be sure to replace the RADIUS_ENDPOINT and PRIVATE_KEY values with your own. See also: Radius testnet access and Create a Private Key.