VM affordances
The Stylus Rust SDK contains several modules for interacting with the Virtual Machine (VM), which can be imported from stylus_sdk.
Let's see an example:
注記
This code has yet to be audited. Please use at your own risk.
use stylus_sdk::{msg};
let callvalue = msg::value();
This page lists the modules that are available, as well as the methods within those modules.
block
Allows you to inspect the current block:
basefee: gets the basefee of the current blockchainid: gets the unique chain identifier of the Arbitrum chaincoinbase: gets the coinbase of the current block, which on Arbitrum chains is the L1 batch poster's addressgas_limit: gets the gas limit of the current blocknumber: gets a bounded estimate of the L1 block number at which the sequencer sequenced the transaction. See Block gas limit, numbers and time for more information on how this value is determinedtimestamp: gets a bounded estimate of the Unix timestamp at which the sequencer sequenced the transaction. See Block gas limit, numbers and time for more information on how this value is determined
use stylus_sdk::{block};
let basefee = block::basefee();
let chainid = block::chainid();
let coinbase = block::coinbase();
let gas_limit = block::gas_limit();
let number = block::number();
let timestamp = block::timestamp();