Encode a CosmWasm smart query through gRPC
A contract expects JSON query bytes, while protobuf JSON represents bytes as base64. Encoding the JSON object at the correct layer avoids a common malformed-request error.
Query token metadata on a compatible contract
Set CONTRACT to a CW20 instance implementing token_info and GRPC to a TLS gRPC endpoint with reflection. Serialize the inner JSON once and base64-encode its bytes for queryData.
DATA=$(printf '%s' '{"token_info":{}}' | base64 | tr -d '\n')
grpcurl -d "{\"address\":\"$CONTRACT\",\"queryData\":\"$DATA\"}" "$GRPC" cosmwasm.wasm.v1.Query/SmartContractState
The response data is also a bytes field. Base64-decode it and parse the resulting contract response as JSON. For this query inspect the token name, symbol and decimals supplied by the contract.
Identify which layer rejected the input
Invalid base64 fails before contract execution. A valid encoding with an unknown variant can reach the contract and return a schema error. Consult the exact query schema for the deployed contract version before changing the gRPC method. github.com wasmd Query API