ERC-1155 (Multi Token) read operations.
Thin wrappers around Onchain.Contract.call/5 for standard ERC-1155 queries.
ERC-1155 is semi-fungible: the same token ID can have multiple owners with
different balances.
Error Format
Errors pass through from underlying modules:
| Source | Error Shape |
|---|---|
Onchain.Address.validate/1 | {:error, {:invalid_address, input}} |
Onchain.Contract.call/5 | {:error, {:encode_error, ...}}, {:error, {:rpc_error, ...}}, {:error, {:decode_error, ...}} |
Functions
| Function | Purpose |
|---|---|
balance_of/4 | Balance of a specific token ID for an owner |
balance_of!/4 | Same, raises on error |
balance_of_batch/4 | Batch balance query for multiple owner/token pairs |
balance_of_batch!/4 | Same, raises on error |
uri/3 | Metadata URI for a token ID |
uri!/3 | Same, raises on error |
approved_for_all?/4 | Whether an operator is approved for all tokens |
approved_for_all!/4 | Same, raises on error |
API Functions
| Function | Arity | Description | Param Kinds |
|---|---|---|---|
approved_for_all! | 4 | Check if an operator is approved for all tokens. Raises on error. | contract: value, owner: value, operator: value, opts: value |
approved_for_all? | 4 | Check if an operator is approved for all tokens of an owner. | contract: value, owner: value, operator: value, opts: value |
uri! | 3 | Get the metadata URI for a token ID. Raises on error. | contract: value, token_id: value, opts: value |
uri | 3 | Get the metadata URI for a token ID. | contract: value, token_id: value, opts: value |
balance_of_batch! | 4 | Batch query balances. Raises on error. | contract: value, owners: value, token_ids: value, opts: value |
balance_of_batch | 4 | Batch query balances for multiple owner/token ID pairs. | contract: value, owners: value, token_ids: value, opts: value |
balance_of! | 4 | Get the balance of a specific token ID for an owner. Raises on error. | contract: value, owner: value, token_id: value, opts: value |
balance_of | 4 | Get the balance of a specific token ID for an owner. | contract: value, owner: value, token_id: value, opts: value |
Summary
Functions
Check if an operator is approved for all tokens. Raises on error.
Check if an operator is approved for all tokens of an owner.
Get the balance of a specific token ID for an owner.
Get the balance of a specific token ID for an owner. Raises on error.
Batch query balances for multiple owner/token ID pairs.
Batch query balances. Raises on error.
Get the metadata URI for a token ID.
Get the metadata URI for a token ID. Raises on error.
Functions
@spec approved_for_all!( String.t() | binary(), String.t() | binary(), String.t() | binary(), keyword() ) :: boolean()
Check if an operator is approved for all tokens. Raises on error.
Parameters
contract- ERC-1155 contract address (value)owner- Token owner address (value)operator- Operator address to check (value)opts- Options: :rpc_url, :timeout, :block (default:[], value)
Returns
Whether the operator is approved for all tokens (boolean)
# descripex:contract
%{
params: %{
owner: %{description: "Token owner address", kind: :value},
opts: %{
default: [],
description: "Options: :rpc_url, :timeout, :block",
kind: :value
},
operator: %{description: "Operator address to check", kind: :value},
contract: %{description: "ERC-1155 contract address", kind: :value}
},
returns: %{
type: :boolean,
description: "Whether the operator is approved for all tokens"
}
}
@spec approved_for_all?( String.t() | binary(), String.t() | binary(), String.t() | binary(), keyword() ) :: {:ok, boolean()} | {:error, term()}
Check if an operator is approved for all tokens of an owner.
Parameters
contract- ERC-1155 contract address (value)owner- Token owner address (value)operator- Operator address to check (value)opts- Options: :rpc_url, :timeout, :block (default:[], value)
Returns
Whether the operator is approved for all tokens ({:ok, boolean()} | {:error, term()})
# descripex:contract
%{
params: %{
owner: %{description: "Token owner address", kind: :value},
opts: %{
default: [],
description: "Options: :rpc_url, :timeout, :block",
kind: :value
},
operator: %{description: "Operator address to check", kind: :value},
contract: %{description: "ERC-1155 contract address", kind: :value}
},
returns: %{
type: "{:ok, boolean()} | {:error, term()}",
description: "Whether the operator is approved for all tokens",
example: "false"
}
}
@spec balance_of( String.t() | binary(), String.t() | binary(), non_neg_integer(), keyword() ) :: {:ok, non_neg_integer()} | {:error, term()}
Get the balance of a specific token ID for an owner.
Parameters
contract- ERC-1155 contract address (value)owner- Address to check balance for (value)token_id- Token ID (non-negative integer) (value)opts- Options: :rpc_url, :timeout, :block (default:[], value)
Returns
Balance of the token ID for the owner ({:ok, non_neg_integer()} | {:error, term()})
# descripex:contract
%{
params: %{
owner: %{description: "Address to check balance for", kind: :value},
opts: %{
default: [],
description: "Options: :rpc_url, :timeout, :block",
kind: :value
},
contract: %{description: "ERC-1155 contract address", kind: :value},
token_id: %{description: "Token ID (non-negative integer)", kind: :value}
},
returns: %{
type: "{:ok, non_neg_integer()} | {:error, term()}",
description: "Balance of the token ID for the owner",
example: "10"
}
}
@spec balance_of!( String.t() | binary(), String.t() | binary(), non_neg_integer(), keyword() ) :: non_neg_integer()
Get the balance of a specific token ID for an owner. Raises on error.
Parameters
contract- ERC-1155 contract address (value)owner- Address to check balance for (value)token_id- Token ID (non-negative integer) (value)opts- Options: :rpc_url, :timeout, :block (default:[], value)
Returns
Balance of the token ID (non_neg_integer)
# descripex:contract
%{
params: %{
owner: %{description: "Address to check balance for", kind: :value},
opts: %{
default: [],
description: "Options: :rpc_url, :timeout, :block",
kind: :value
},
contract: %{description: "ERC-1155 contract address", kind: :value},
token_id: %{description: "Token ID (non-negative integer)", kind: :value}
},
returns: %{type: :non_neg_integer, description: "Balance of the token ID"}
}
@spec balance_of_batch( String.t() | binary(), [String.t() | binary()], [non_neg_integer()], keyword() ) :: {:ok, [non_neg_integer()]} | {:error, term()}
Batch query balances for multiple owner/token ID pairs.
Parameters
contract- ERC-1155 contract address (value)owners- List of owner addresses (must match token_ids length) (value)token_ids- List of token IDs (must match owners length) (value)opts- Options: :rpc_url, :timeout, :block (default:[], value)
Returns
List of balances corresponding to each owner/token_id pair ({:ok, [non_neg_integer()]} | {:error, term()})
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :rpc_url, :timeout, :block",
kind: :value
},
contract: %{description: "ERC-1155 contract address", kind: :value},
owners: %{
description: "List of owner addresses (must match token_ids length)",
kind: :value
},
token_ids: %{
description: "List of token IDs (must match owners length)",
kind: :value
}
},
returns: %{
type: "{:ok, [non_neg_integer()]} | {:error, term()}",
description: "List of balances corresponding to each owner/token_id pair",
example: "[10, 0, 5]"
}
}
@spec balance_of_batch!( String.t() | binary(), [String.t() | binary()], [non_neg_integer()], keyword() ) :: [non_neg_integer()]
Batch query balances. Raises on error.
Parameters
contract- ERC-1155 contract address (value)owners- List of owner addresses (must match token_ids length) (value)token_ids- List of token IDs (must match owners length) (value)opts- Options: :rpc_url, :timeout, :block (default:[], value)
Returns
List of balances ([non_neg_integer()])
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :rpc_url, :timeout, :block",
kind: :value
},
contract: %{description: "ERC-1155 contract address", kind: :value},
owners: %{
description: "List of owner addresses (must match token_ids length)",
kind: :value
},
token_ids: %{
description: "List of token IDs (must match owners length)",
kind: :value
}
},
returns: %{type: "[non_neg_integer()]", description: "List of balances"}
}
@spec uri(String.t() | binary(), non_neg_integer(), keyword()) :: {:ok, String.t()} | {:error, term()}
Get the metadata URI for a token ID.
Parameters
contract- ERC-1155 contract address (value)token_id- Token ID (non-negative integer) (value)opts- Options: :rpc_url, :timeout, :block (default:[], value)
Returns
Token metadata URI (may contain {id} placeholder per ERC-1155 spec) ({:ok, String.t()} | {:error, term()})
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :rpc_url, :timeout, :block",
kind: :value
},
contract: %{description: "ERC-1155 contract address", kind: :value},
token_id: %{description: "Token ID (non-negative integer)", kind: :value}
},
returns: %{
type: "{:ok, String.t()} | {:error, term()}",
description: "Token metadata URI (may contain {id} placeholder per ERC-1155 spec)",
example: "\"https://token-cdn-domain/{id}.json\""
}
}
@spec uri!(String.t() | binary(), non_neg_integer(), keyword()) :: String.t()
Get the metadata URI for a token ID. Raises on error.
Parameters
contract- ERC-1155 contract address (value)token_id- Token ID (non-negative integer) (value)opts- Options: :rpc_url, :timeout, :block (default:[], value)
Returns
Token metadata URI (string)
# descripex:contract
%{
params: %{
opts: %{
default: [],
description: "Options: :rpc_url, :timeout, :block",
kind: :value
},
contract: %{description: "ERC-1155 contract address", kind: :value},
token_id: %{description: "Token ID (non-negative integer)", kind: :value}
},
returns: %{type: :string, description: "Token metadata URI"}
}