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

Go

PreviousCommand lineNextJavaScript

Last updated 2 months ago

Was this helpful?

1

Create a new Go project:

go mod init example/radius
2

Install the Radius Go SDK:

go get github.com/radiustechsystems/sdk/go
3

Create a Go file called main.go:

package main

import (
	"context"
	"log"
	"math/big"

	"github.com/radiustechsystems/sdk/go/radius"
)

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

func main() {
	client, err := radius.NewClient(RADIUS_ENDPOINT)
	account := radius.NewAccount(radius.WithPrivateKeyHex(PRIVATE_KEY, client))
	recipient, err := radius.AddressFromHex("0x...") // Replace with recipient address
	amount := big.NewInt(100)
	receipt, err := account.Send(context.Background(), client, recipient, amount)
	
	log.Printf("Transaction hash: %s", receipt.TxHash.Hex())
}
4

Run the code using the following command:

go run main.go
1

Create a new Go project:

go mod init example/radius
2

Create a Go file called main.go:

package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

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

func main() {
	payload := map[string]interface{}{
		"jsonrpc": "2.0",
		"method":  "eth_blockNumber",
		"params":  []string{},
		"id":      1,
	}

	jsonPayload, err := json.Marshal(payload)
	if err != nil {
		fmt.Println("Error marshalling JSON:", err)
		return
	}

	resp, err := http.Post(url, "application/json", bytes.NewBuffer(jsonPayload))
	if err != nil {
		fmt.Println("Error sending request:", err)
		return
	}
	defer func(Body io.ReadCloser) {
		err = Body.Close()
		if err != nil {

		}
	}(resp.Body)

	body, err := io.ReadAll(resp.Body)
	if err != nil {
		fmt.Println("Error reading response:", err)
		return
	}

	var result map[string]interface{}
	err = json.Unmarshal(body, &result)
	if err != nil {
		fmt.Println("Error parsing JSON response:", err)
		return
	}

	fmt.Println(result)
}
3

Run the code using the following command:

go run main.go
1

Create a new Go project:

go mod init example/radius
2

Create a Go file called main.go:

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/ethereum/go-ethereum/ethclient"
)

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

func main() {
	client, err := ethclient.Dial(url)
	if err != nil {
		log.Fatalf("Failed to connect to the Radius client: %v", err)
	}
	defer client.Close()

	blockNumber, err := client.BlockNumber(context.Background())
	if err != nil {
		log.Fatalf("Failed to retrieve block number: %v", err)
	}

	fmt.Printf("Latest block number: %d\n", blockNumber)
}
3

Add the module requirements to your go.mod file:

go mod tidy
4

Run the code using the following command:

go run main.go

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