Skip to content
/ pwrgo Public

PWR Go is a Go library for interacting with the PWR network

License

Notifications You must be signed in to change notification settings

pwrlabs/pwrgo

Repository files navigation

PWR Chain GO SDK

PWR Go is a Go library for interacting with the PWR network. It provides an easy interface for wallet management and sending transactions on PWR.

🌐 Documentation

How to Guides 🔜 & API 💻

Play with Code Examples 🎮

💫 Getting Started

Import the library:

import (
    "fmt"
    "github.com/pwrlabs/pwrgo/rpc"
    "github.com/pwrlabs/pwrgo/wallet"
)

Set your RPC node:

rpc.SetRpcNodeUrl("https://pwrrpc.pwrlabs.io") // optional

Import wallet by PK:

var privateKeyHex = "0xac0974bec...f80"
var wallet = wallet.FromPrivateKey(privateKeyHex)

Get wallet address:

var address = wallet.GetAddress()

Get wallet balance:

var balance = wallet.GetBalance()

Transfer PWR tokens:

var transferTx = wallet.TransferPWR("recipientAddress", 1000)

Sending a transcation to the PWR Chain returns a Response object, which specified if the transaction was a success, and returns relevant data. If the transaction was a success, you can retrieive the transaction hash, if it failed, you can fetch the error.

package main
import (
    "fmt"
    "github.com/pwrlabs/pwrgo/rpc"
    "github.com/pwrlabs/pwrgo/wallet"
)
func main() {
    var privateKeyHex = "0xac0974bec...f80"
    var wallet = wallet.FromPrivateKey(privateKeyHex)

    var transferTx = wallet.TransferPWR("recipientAddress", 1000)
    if transferTx.Success {
        fmt.Printf("Transfer tx hash: %s\n", transferTx.TxHash)
    } else {
        fmt.Println("Error sending Transfer tx:", transferTx.Error)
    }
}

Send data to a VM:

package main
import (
    "fmt"
    "github.com/pwrlabs/pwrgo/rpc"
    "github.com/pwrlabs/pwrgo/wallet"
)
func main() {
    var privateKeyHex = "0xac0974bec...f80"
    var wallet = wallet.FromPrivateKey(privateKeyHex)

    var data = []byte("Hello world")
    var vmTxResponses = wallet.SendVMData(123, data)
    if vmTxResponses.Success {
        fmt.Printf("Sending tx hash: %s\n", vmTxResponses.TxHash)
    } else {
        fmt.Println("Error sending VM data tx:", vmTxResponses.Error)
    }
}

Other Static Calls

Get RPC Node Url:

Returns currently set RPC node URL.

var url = rpc.GetRpcNodeUrl()

**Get Fee Per Byte: **

Gets the latest fee-per-byte rate.

var fee = rpc.GetFeeBerByte()

Get Balance Of Address:

Gets the balance of a specific address.

var balance = rpc.GetBalanceOfAddress("0x...")

Get Nonce Of Address:

Gets the nonce/transaction count of a specific address.

var nonce = rpc.GetNonceOfAddress("0x...")

✏️ Contributing

If you consider to contribute to this project please read CONTRIBUTING.md first.

You can also join our dedicated channel for pwr-rs on the PWR Chain Discord

📜 License

Copyright (c) 2024 PWR Labs

Licensed under the MIT license.

About

PWR Go is a Go library for interacting with the PWR network

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages