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.
Play with Code Examples 🎮
Import the library:
import (
"fmt"
"github.com/pwrlabs/pwrgo/rpc"
"github.com/pwrlabs/pwrgo/wallet"
)
Set your RPC node:
var pwr = rpc.SetRpcNodeUrl("https://pwrrpc.pwrlabs.io")
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.Hash)
} 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.Hash)
} else {
fmt.Println("Error sending VM data tx:", vmTxResponses.Error)
}
}
Get RPC Node Url:
Returns currently set RPC node URL.
var url = pwr.GetRpcNodeUrl()
Get Fee Per Byte:
Gets the latest fee-per-byte rate.
var fee = pwr.GetFeeBerByte()
Get Balance Of Address:
Gets the balance of a specific address.
var balance = pwr.GetBalanceOfAddress("0x...")
Get Nonce Of Address:
Gets the nonce/transaction count of a specific address.
var nonce = pwr.GetNonceOfAddress("0x...")
If you consider to contribute to this project please read CONTRIBUTING.md first.
You can also join our dedicated channel for developers on the PWR Chain Discord
Copyright (c) 2025 PWR Labs
Licensed under the MIT license.