This question is continued from How to get ASTR balance via json rpc.

I understood calculating StorageKey from Publickey is needed. It seems that calculating StorageKey and decoding rpc-json responses are complicated tasks, so I decided to use the following the library. https://github.com/centrifuge/go-substrate-rpc-client

I wrote the following GO code and got response, but the $ASTR balance of the response is different from the one found in Subscan. https://astar.subscan.io/account/Y29MvHDrJyTiNPWYK5r5LouPdc7kkquZe9c6WfpQLvN4wwj The response is below. I expected Free field is 246,291,284.31933627. Free field type is big.Int, so I tried to call String() to convert this to human-readable value, but it showed the same result. Give me thought about getting $ASTR balance from this response?


The code is here.

pubkey := "0x5c2aa08039c510dbd98643e132a3c82475a09814203d631b44fe530d0208dc66"
api, err := gsrpc.NewSubstrateAPI("https://astar-rpc.dwellir.com")
meta, err := api.RPC.State.GetMetadataLatest()
accountID, err := types.NewAccountIDFromHexString(pubkey)
key, err := types.CreateStorageKey(meta, "System", "Account", accountID.ToBytes())
var accountInfo types.AccountInfo
ok, err := api.RPC.State.GetStorageLatest(key, &accountInfo)
fmt.Printf("%+v", accountInfo)

1 Answer 1


I think the go-substrate-rpc-client was no more under maintain.

Here is their account data type: https://github.com/centrifuge/go-substrate-rpc-client/blob/ccecb66ef9132c2cea5be0d6aab89a8ca8b00851/types/account_data.go#L19-L30

Here is the latest Substrate code: https://github.com/paritytech/substrate/blob/f0b6e79a8d21856743acc5370b5d5c3271048cb9/frame/system/src/lib.rs#L733-L750

As you can see, they don't have the sufficients field.

So there are 4 bytes shifted. Then the scale-codec got a weird result.

BTW, if you think my previous answer solved your problem, please mark it as the answer. Thanks.

  • Thanks a lot! You answer is really helpful. I solved this issue by defining account data type with the following. And I marked your this answer, but I couldn't find the green check button on the old post. type ModifiedAccountInfo struct { Nonce types.U32 Consumers types.U32 Providers types.U32 Sufficients types.U32 Data struct { Free types.U128 Reserved types.U128 MiscFrozen types.U128 FreeFrozen types.U128 } }
    – user3563
    Commented Dec 9, 2022 at 14:03
  • Last time I used that the official advice was to define your own AccountData… Commented Dec 10, 2022 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.