Quick start
View SourceThis page takes you from nothing to a component called from Erlang, its JSON Schema, and a registry, in about five minutes. Read it first; the other pages go deeper into each step.
1. Add the dependency
{deps, [{wasm_tools, "~> 0.1", {pkg, erlang_wasm_tools}}]}.Start it with your application, or in a shell:
{ok, _} = application:ensure_all_started(wasm_tools).2. Get a component
Any WebAssembly component works. This repository ships one,
test/fixtures/component/calculator.component.wasm, built from this WIT:
package example:calculator;
world calculator {
export add: func(a: s32, b: s32) -> s32;
export multiply: func(a: s32, b: s32) -> s32;
}Write your first component builds it from Rust.
3. Look inside without running it
Path = "test/fixtures/component/calculator.component.wasm",
{ok, #{exports := [Add | _]}} = wasm_tools:inspect({file, Path}),
maps:with([name, params, result], Add).
%% => #{name := <<"add">>, params := [{<<"a">>, s32}, {<<"b">>, s32}], result := s32}4. Load it and call it
{ok, Calc} = wasm_tools:load({file, Path}),
wasm_tools:call(Calc, <<"add">>, #{<<"a">> => 20, <<"b">> => 22}).
%% => {ok, 42}Arguments are a map keyed by parameter name. A value that does not fit its type is refused before the component runs:
wasm_tools:call(Calc, <<"add">>, #{<<"a">> => 1 bsl 40, <<"b">> => 1}).
%% => {error, #{class := argument, msg := <<"integer out of range">>, ctx := #{path := [<<"a">>], expected := s32}}}5. Get its JSON Schema
{ok, #{input := Input}} = wasm_tools:schema(Calc, <<"add">>),
maps:get(<<"required">>, Input).
%% => [<<"a">>, <<"b">>]6. Put it in a registry
A registry holds tools from many components under names you choose, in a process you supervise:
{ok, Reg} = wasm_tools:start_link(#{}),
{ok, [<<"calc_add">>, <<"calc_multiply">>]} =
wasm_tools:add(Reg, Calc, #{namespace => <<"calc">>}),
wasm_tools:call(Reg, <<"calc_multiply">>, #{<<"a">> => 6, <<"b">> => 7}).
%% => {ok, 42}unlink(Reg),
ok = wasm_tools:stop(Reg),
ok = wasm_tools:unload(Calc).Next
- Call a component: every value type, errors, deadlines.
- Capabilities and security: what a component may reach.
- MCP: the same tools for AI agents.