referrerpolicy=no-referrer-when-downgrade

polkadot_sdk_docs/reference_docs/
custom_host_functions.rs

1//! # Custom Host Functions
2//!
3//! Host functions are functions that the wasm instance can use to communicate with the node. Learn
4//! more about this in [`crate::reference_docs::wasm_meta_protocol`].
5//!
6//! ## Finding Host Functions
7//!
8//! To declare a set of functions as host functions, you need to use the `#[runtime_interface]`
9//! ([`sp_runtime_interface`]) attribute macro. The most notable set of host functions are those
10//! that allow the runtime to access the chain state, namely [`sp_io::storage`]. Some other notable
11//! host functions are also defined in [`sp_io`].
12//!
13//! ## Adding New Host Functions
14//!
15//! > Adding a new host function is a big commitment and should be done with care. Namely, the nodes
16//! > in the network need to support all host functions forever in order to be able to sync
17//! > historical blocks.
18//!
19//! Adding host functions is only possible when you are using a node-template, so that you have
20//! access to the boilerplate of building your node.
21//!
22//! A group of host functions can always be grouped to gether as a tuple:
23#![doc = docify::embed!("../../substrate/primitives/io/src/lib.rs", SubstrateHostFunctions)]
24//!
25//! The host functions are attached to the node side's [`sc_executor::WasmExecutor`]. For example in
26//! the minimal template, the setup looks as follows:
27#![doc = docify::embed!("../../templates/minimal/node/src/service.rs", FullClient)]