Created
January 28, 2021 16:03
-
-
Save ChinmayPatel/ad4b34a6b835c362268531fdf8c7e767 to your computer and use it in GitHub Desktop.
Check Balance using Centrifuge GRPC library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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