Go
Last updated
Was this helpful?
Last updated
Was this helpful?
Create a new Go project:
go mod init example/radius
Install the Radius Go SDK:
go get github.com/radiustechsystems/sdk/go
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())
}
Run the code using the following command:
go run main.go
Create a new Go project:
go mod init example/radius
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)
}
Run the code using the following command:
go run main.go
Create a new Go project:
go mod init example/radius
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)
}
Add the module requirements to your go.mod
file:
go mod tidy
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.