Skip to main content

Querying On-Chain State (JSON APIs)

Gno.land exposes a set of ABCI query endpoints that return structured JSON representations of on-chain state. These are designed for programmatic access by frontends, explorers, and developer tools — as opposed to the text-oriented endpoints documented in Interacting with gnokey.

All endpoints are accessed via ABCIQuery with path vm/<endpoint> and a -data payload. They return Amino JSON, the standard encoding used by Gno's type system.

Endpoints

EndpointDataReturns
vm/qeval_json<pkgpath>.<Expr>Amino JSON of the evaluated expression
vm/qpkg_json<pkgpath>Named top-level variables of a package
vm/qobject_json<objectid>Children of a persisted object
vm/qtype_json<typeid>Type definition (struct fields, etc.)

vm/qeval_json

Evaluates an expression in read-only mode and returns the result as Amino JSON instead of a printed string. This is the JSON counterpart to vm/qeval.

gnokey query vm/qeval_json --data 'gno.land/r/demo/counter.GetCounter()'
[{"T":{"@type":"/gno.PrimitiveType","value":"32"},"V":{"@type":"/gno.StringValue","value":"10"}}]

The response is an array of TypedValue objects — one per return value. See Amino JSON format below.

vm/qpkg_json

Returns the named top-level variables of a package as an object with names and values arrays. This is the entry point for exploring a package's state.

gnokey query vm/qpkg_json --data 'gno.land/r/demo/counter'
{
"names": ["counter", "Increment", "Render"],
"values": [
{"T":{"@type":"/gno.PrimitiveType","value":"32"},"V":{"@type":"/gno.StringValue","value":"10"}},
{"T":{"@type":"/gno.FuncType", ...},"V":{"@type":"/gno.FuncValue", ...}},
{"T":{"@type":"/gno.FuncType", ...},"V":{"@type":"/gno.FuncValue", ...}}
]
}

Each entry in values corresponds to the same index in names. Variables that hold persisted objects (structs, slices, maps, etc.) will contain a RefValue with an ObjectID that can be drilled into with vm/qobject_json.

vm/qobject_json

Retrieves the fields or elements of a persisted object by its ObjectID. Use this to drill into values returned by vm/qpkg_json or other objects.

gnokey query vm/qobject_json --data '0186fce2acb457084a538e1c8b26f0f2b30e1d44:2'
[
{"N":"AQAAAAAAAAA=","T":{"@type":"/gno.PrimitiveType","value":"4"}},
{"T":{"@type":"/gno.PointerType", ...},"V":{"@type":"/gno.PointerValue", ...}},
{"T":{"@type":"/gno.PrimitiveType","value":"32"},"V":{"@type":"/gno.StringValue","value":"5"}}
]

The response is an array of TypedValue objects — one per field (for structs) or element (for arrays/slices). Struct fields are returned by index; use vm/qtype_json to resolve field names.

vm/qtype_json

Retrieves a type definition by its TypeID. Primarily used to resolve struct field names for objects returned by vm/qobject_json.

gnokey query vm/qtype_json --data 'gno.land/p/demo/avl.Node'
{
"typeid": "gno.land/p/demo/avl.Node",
"type": {
"@type": "/gno.DeclaredType",
"PkgPath": "gno.land/p/demo/avl",
"Name": "Node",
"Base": {
"@type": "/gno.StructType",
"Fields": [
{"Name": "key", "Type": {"@type": "/gno.PrimitiveType", "value": "16"}},
{"Name": "value", "Type": {"@type": "/gno.InterfaceType"}},
{"Name": "height", "Type": {"@type": "/gno.PrimitiveType", "value": "256"}},
{"Name": "size", "Type": {"@type": "/gno.PrimitiveType", "value": "32"}},
{"Name": "leftNode", "Type": {"@type": "/gno.PointerType", ...}},
{"Name": "rightNode", "Type": {"@type": "/gno.PointerType", ...}}
],
...
},
...
}
}

Amino JSON Format

All JSON endpoints use Amino encoding — Gno's native type serialization. Each value is represented as a TypedValue with up to three fields:

FieldDescription
TType descriptor with an @type discriminator
VValue payload (strings, structs, refs, etc.)
NBase64-encoded 8-byte little-endian numeric value (for primitives)

Type discriminators (T.@type)

@typeKind
/gno.PrimitiveTypebool, int, uint, string, etc. (value is the numeric kind ID)
/gno.PointerTypePointer to another type
/gno.ArrayTypeFixed-length array
/gno.SliceTypeSlice
/gno.StructTypeStruct with named fields
/gno.MapTypeMap
/gno.FuncTypeFunction signature
/gno.InterfaceTypeInterface
/gno.DeclaredTypeNamed type wrapping a base type
/gno.RefTypeLazy reference to a type (resolved via qtype_json)

Value discriminators (V.@type)

@typeDescription
/gno.StringValueString value
/gno.StructValueInline struct fields
/gno.ArrayValueInline array elements
/gno.SliceValueSlice with base/offset/length/maxcap
/gno.PointerValuePointer to a value
/gno.MapValueMap with key-value list
/gno.FuncValueFunction closure
/gno.RefValueReference to a persisted object (has ObjectID)
/gno.TypeValueReified type

Primitive type IDs

The PrimitiveType value field is a numeric ID (powers of 2):

IDTypeIDType
4bool2048uint
16string4096uint8
32int8192uint16
64int832768uint32
128int1665536uint64
512int321048576float32
1024int642097152float64

Primitive values are encoded in the N field as base64 of an 8-byte little-endian integer (for numerics and bool), or in the V field as a StringValue (for strings, and for int/uint which may exceed 64 bits).

Lazy references

Large or nested values are not inlined — they are replaced with RefValue:

{"V": {"@type": "/gno.RefValue", "ObjectID": "0186fce2...:4"}}

Use vm/qobject_json with the ObjectID to fetch the object's contents.

Similarly, declared types may appear as RefType:

{"T": {"@type": "/gno.RefType", "ID": "gno.land/p/demo/avl.Node"}}

Use vm/qtype_json with the ID to resolve the type definition.

Traversal Pattern

A typical client traverses the state tree as follows:

  1. vm/qpkg_json — get named package variables
  2. For each variable with a RefValue, call vm/qobject_json with its ObjectID
  3. If the object's type is a RefType, call vm/qtype_json with its ID to get struct field names
  4. Repeat step 2 recursively for nested RefValue references

This lazy-loading pattern avoids transferring the entire object graph upfront.

Client Libraries

  • @gnojs/amino — TypeScript library that decodes Amino JSON into a navigable tree of StateNode objects. Handles all value types, primitive decoding, and struct field name resolution.
  • gnoclient — Go client (use ABCIQuery with the paths above)
  • gno-js-client / tm2-js-client — JavaScript/TypeScript clients for RPC access

See Also