Skip to content

Instantly share code, notes, and snippets.

@ChinmayPatel
Created January 28, 2021 16:03
Show Gist options
  • Save ChinmayPatel/ad4b34a6b835c362268531fdf8c7e767 to your computer and use it in GitHub Desktop.
Save ChinmayPatel/ad4b34a6b835c362268531fdf8c7e767 to your computer and use it in GitHub Desktop.
Check Balance using Centrifuge GRPC library
package main
import (
"fmt"
gsrpc "github.com/centrifuge/go-substrate-rpc-client"
"github.com/centrifuge/go-substrate-rpc-client/types"
)
func main() {
getBalance();
}
func getBalance() {
api, err := gsrpc.NewSubstrateAPI("wss://westend-rpc.polkadot.io");
if err != nil {
panic(err)
}
opts := types.SerDeOptions{NoPalletIndices: true}
types.SetSerDeOptions(opts)
meta, err := api.RPC.State.GetMetadataLatest()
if err != nil {
panic(err)
}
testAccount, err := types.HexDecodeString("0x9ae581fef1fc06828723715731adcf810e42ce4dadad629b1b7fa5c3c144a81d");
if err != nil {
panic(err)
}
key, err := types.CreateStorageKey(meta, "System", "Account", testAccount, nil)
if err != nil {
panic(err)
}
var accountInfo types.AccountInfo
ok, err := api.RPC.State.GetStorageLatest(key, &accountInfo)
if err != nil || !ok {
panic(err)
}
fmt.Printf("Account Info", accountInfo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment