Transaction procedures
There are user-facing procedures and kernel procedures. Users don’t directly invoke kernel procedures, but instead they invoke them indirectly via account code, note, or transaction scripts. In these cases, kernel procedures are invoked by a syscall
instruction which always executes in the kernel context.
User-facing procedures (APIs)¶
These procedures can be used to create smart contract/account code, note scripts, or account scripts. They basically serve as an API for the underlying kernel procedures. If a procedure can be called in the current context, an exec
is sufficient. Otherwise the context procedures must be invoked by call
. Users never need to invoke syscall
procedures themselves.
Tip
If capitalized, a variable representing a word
, e.g., ACCT_HASH
consists of four felts
. If lowercase, the variable is represented by a single felt
.
Account¶
To import the account procedures, set use.miden::account
at the beginning of the file.
Any procedure that changes the account state must be invoked in the account context and not by note or transaction scripts. All procedures invoke syscall
to the kernel API and some are restricted by the kernel procedure exec.authenticate_account_origin
, which fails if the parent context is not the executing account.
Procedure name | Stack | Output | Context | Description |
---|---|---|---|---|
get_id |
[] |
[acct_id] |
account, note |
|
get_nonce |
[] |
[nonce] |
account, note |
|
get_initial_hash |
[] |
[H] |
account, note |
|
get_current_hash |
[] |
[ACCT_HASH] |
account, note |
|
incr_nonce |
[value] |
[] |
account |
|
get_item |
[index] |
[VALUE] |
account, note |
|
set_item |
[index, V'] |
[R', V] |
account |
|
set_code |
[CODE_COMMITMENT] |
[] |
account |
|
get_balance |
[faucet_id] |
[balance] |
account, note |
|
has_non_fungible_asset |
[ASSET] |
[has_asset] |
account, note |
|
add_asset |
[ASSET] |
[ASSET'] |
account |
|
remove_asset |
[ASSET] |
[ASSET] |
account |
|
get_vault_commitment |
[] |
[COM] |
account, note |
|
Note¶
To import the note procedures, set use.miden::note
at the beginning of the file. All procedures are restricted to the note context.
Procedure name | Inputs | Outputs | Context | Description |
---|---|---|---|---|
get_assets |
[dest_ptr] |
[num_assets, dest_ptr] |
note |
|
get_inputs |
[dest_ptr] |
[dest_ptr] |
note |
|
get_sender |
[] |
[sender] |
note |
|
compute_inputs_hash |
[inputs_ptr, num_inputs] |
[HASH] |
note |
|
Tx¶
To import the transaction procedures set use.miden::tx
at the beginning of the file. Only the create_note
procedure is restricted to the account context.
Procedure name | Inputs | Outputs | Context | Description |
---|---|---|---|---|
get_block_number |
[] |
[num] |
account, note |
|
get_block_hash |
[] |
[H] |
account, note |
|
get_input_notes_hash |
[] |
[COM] |
account, note |
|
get_output_notes_hash |
[0, 0, 0, 0] |
[COM] |
account, note |
|
create_note |
[ASSET, tag, RECIPIENT] |
[ptr] |
account |
|
Asset¶
To import the asset procedures set use.miden::asset
at the beginning of the file. These procedures can only be called by faucet accounts.
Procedure name | Stack | Output | Context | Description |
---|---|---|---|---|
build_fungible_asset |
[faucet_id, amount] |
[ASSET] |
faucet |
|
create_fungible_asset |
[amount] |
[ASSET] |
faucet |
|
build_non_fungible_asset |
[faucet_id, DATA_HASH] |
[ASSET] |
faucet |
|
create_non_fungible_asset |
[DATA_HASH] |
[ASSET] |
faucet |
|
Faucet¶
To import the faucet procedures, set use.miden::faucet
at the beginning of the file.
Procedure name | Stack | Outputs | Context | Description |
---|---|---|---|---|
mint |
[ASSET] |
[ASSET] |
faucet |
|
burn |
[ASSET] |
[ASSET] |
faucet |
|
get_total_issuance |
[] |
[total_issuance] |
faucet |
|