Host functions
A module can import only these functions. Every SDK wraps them; the raw ABI is listed for reference.
| Host import | What it does | Rust | Go | AssemblyScript | JS engine | Python |
|---|---|---|---|---|---|---|
storage.get |
Read a key of this module’s state | storage::get, get_string, get_json |
StorageGet, StorageGetString, StorageGetJSON |
storage.get(key) ("" if unset) |
storage.get, db.get(key, default) |
hive.storage.get, hive.db.get(key, default) |
storage.set |
Write a key (an empty value deletes it) | storage::set, set_json |
StorageSet, StorageSetString, StorageSetJSON |
storage.set(key, value) |
storage.set, db.set |
hive.storage.set, hive.db.set |
storage.del |
Delete a key | storage::del |
StorageDel |
storage.del |
storage.del / db.del |
hive.storage.delete / hive.db.delete |
hive.emit |
Record an event {name, data} |
emit(name, &data) |
Emit, EmitRaw |
hive.emit(name, dataJson) |
hive.emit(name, data) |
hive.emit(name, data) |
hive.call |
Call another deployed module synchronously | call, call_json |
Call, CallJSON |
hive.call, hive.tryCall, hive.tryCallRaw |
hive.call, hive.callRaw, hive.tryCall |
hive.call, hive.call_raw, hive.try_call |
crypto.hash |
Keccak-256 of bytes, as 0x + 64 hex |
hash(&[u8]) |
Hash(data) |
hive.hash(data) |
hive.hash(data) |
hive.hash(data) |
console.log |
Debug log on the node (no consensus effect) | log(&str) |
Log, Logf |
hive.log(msg) |
hive.log(…), console.log(…), ctx.log.info(…) |
hive.log(…), ctx.log.info(…) |
hive.abort |
Fail the call with a message | abort(&str), or return Err |
Abort(msg), or return an error |
hive.fail(msg) |
hive.fail(msg) or throw |
hive.fail(msg) or raise |
Storage
Section titled “Storage”- State is a key/value map private to the module (namespaced by its address). A module can never read
or write another module’s keys; use
hive.callto ask the other module. - Keys are 1–256 bytes, values up to 64 KiB, at most 1 MiB written per top-level call.
- Writes are buffered and committed only if the whole top-level call succeeds. A failed call (error, abort, trap, out of gas) writes nothing and emits nothing.
- Storage exists only for modules run through validator rounds (
/v1/execute). Committee workers are stateless. Two ways to run a module
Events
Section titled “Events”- Name:
[A-Za-z0-9_.:-]{1,64}. Data: JSON that canonical JSON accepts: no floats, integers within ±(2^53−1). Use integer minor units (cents, micro-units) or strings. - Up to 64 events per call, 16 KiB of data each. Events are part of the receipt (
events_hash). - Function outputs are plain UTF-8 text and may contain any JSON, floats included; only events and signed structures are restricted.
hive.call
Section titled “hive.call”- The callee runs in a fresh instance with all remaining gas; what it uses is charged to the caller.
- Callee success: its state writes and events merge into the caller’s call. Callee failure: they are discarded and the caller gets an error code it can handle.
- Depth limit 8. The call is synchronous and atomic with the caller.
| Code | Meaning |
|---|---|
-1 |
Module not found |
-2 |
Function not found |
-3 |
Callee failed (trap, abort, error) |
-4 |
Reserved: out of gas always fails the whole call |
-5 |
Call depth exceeded |
-6 |
Malformed address |
Example of cross-language calls: Cross-module composition.
Inputs and outputs
Section titled “Inputs and outputs”The input is a byte string, usually JSON. Through the API, a string input is passed byte for byte and any other JSON value is passed as canonical JSON (floats are rejected; send them inside a string). Outputs must be valid UTF-8 and at most 1 MiB.