Use golang sign transaction

does anyone provide an example of golang using private key strings to sign one transactions and HRC20 transactions? Thanks

1 Like

You can check out the go sdk here.

package main

import (
	"fmt"

	"github.com/harmony-one/go-sdk/pkg/common"
	"github.com/harmony-one/harmony/common/denominations"
	"github.com/harmony-one/harmony/numeric"

	"github.com/harmony-one/go-sdk/pkg/rpc"
)

var (
	nanoAsDec = numeric.NewDec(denominations.Nano)
	oneAsDec  = numeric.NewDec(denominations.One)
)

func main() {
	node := "https://rpc.s0.b.hmny.io"
	address := "one1zvtdhx0yx2uyx8ps363tx4xmn59n2twjp7dkj3"
	balanceRPCReply, err := rpc.Request(rpc.Method.GetBalance, node, []interface{}{address, "latest"})
	if err != nil {
		panic(err)
	}
	fmt.Println(balanceRPCReply["result"].(string))
	//nodeRPCReply, err := rpc.Request(rpc.Method.GetShardID, node, []interface{}{})
	//if err != nil {
	//	panic(err)
	//}
	balance, _ := balanceRPCReply["result"].(string)
	bln := common.NewDecFromHex(balance)
	bln = bln.Quo(oneAsDec)
	fmt.Println(bln.String())
}