Expand description
ewasm_api is a library used to interface with Ethereum’s EEI in Ewasm, a set of enhancements to the Ethereum smart contract platform. ewasm_api exposes both a set of unsafe “native” functions representing the actual EEI functions, and a set of safe wrappers around them. It is recommended not to use the native functions as they do not perform bounds-checking.
To use ewasm_api, simply include it as a dependency in your project. ewasm_api can be built with various feature sets:
default
: Builds withwee_alloc
as the global allocator and with the Rust standard library.qimalloc
: Builds with qimalloc as the global allocator.debug
: Exposes the debugging interface.experimental
: Exposes the experimental bignum system library API.
§Examples
use ewasm_api::prelude::*;
fn entry() {
let a: Hash = block_hash(1);
finish_data(&a.bytes);
}
ewasm_entry_point!(entry);
Using lower-level primitives:
ⓘ
use ewasm_api::{types::Hash, block_hash, finish_data};
#[cfg(target_arch = "wasm32")]
#[no_mangle]
pub extern "C" fn main() {
let a: types::Hash = block_hash(1);
finish_data(&a.bytes);
}
Modules§
- prelude
- Re-export of all the basic features.
- types
- High-level types commonly used in Ethereum contracts.
Macros§
- ewasm_
entry_ point - Declare entry point for a contract. Expects a Rust function name to be executed. This will only compile in when using the wasm32 target.
Enums§
- Call
Result - Enum describing the result of a call. Used by
call
,callCode
,callDelegate
, andcallStatic
. - Create
Result - Enum describing the result of
create
. On success, the data contained is the address of the newly created contract. - Error
- Enum representing an error code for EEI calls. Currently used by
codeCopy
,callDataCopy
,externalCodeCopy
, andreturnDataCopy
.
Functions§
- abort
- Halts execution, reverts all changes to the state and consumes all gas.
- block_
coinbase - Returns the beneficiary address for the block this transaction is in (current block)
- block_
difficulty - Returns the difficulty of the most recent block.
- block_
gas_ limit - Returns the gas limit of the most recent block.
- block_
hash - Returns the hash of the
number
th most recent block. - block_
number - Returns the number of the most recent block.
- block_
timestamp - Returns the timestamp of the most recent block.
- call_
code - Executes another account’s code in the context of the caller.
- call_
delegate - Executes a call similar to
call_code
, but retaining the currently executing call’s sender and value. - call_
mutable - Executes a standard call to the specified address with the given gas limit, ether value, and data.
- call_
static - Executes a static call which cannot mutate the state.
- calldata_
acquire - Returns a vector containing all data passed with the currently executing call.
- calldata_
copy - Returns the segment of call data beginning at
from
, and continuing forlength
bytes. - calldata_
size - Returns the length of the call data supplied with the currently executing call.
- caller
- Returns the sender of the currently executing call.
- callvalue
- Returns the value sent with the currently executing call.
- code_
acquire - Returns the currently executing code.
- code_
copy - Copies the segment of running code beginning at
from
and continuing forlength
bytes. - code_
size - Returns the size of the currently executing code.
- consume_
gas - Subtracts the given amount from the VM’s gas counter. This is usually injected by the metering contract at deployment time, and hence is unneeded in most cases.
- create
- Creates a contract with the the given code, sending the specified ether value to its address.
- current_
address - Returns the executing address.
- external_
balance - Returns the balance of the address given.
- external_
code_ acquire - Returns the code at the specified address.
- external_
code_ copy - Returns the segment of code at
address
beginning atfrom
and continuing forlength
bytes. - external_
code_ size - Returns the size of the code at the specified address.
- finish
- Ends execution, signalling success.
- finish_
data - Fills the return buffer with the given data and halts execution, signalling success.
- gas_
left - Returns the gas left in the current call.
- log0
- Appends log data without a topic.
- log1
- Appends log data with one topic.
- log2
- Appends log data with two topics.
- log3
- Appends log data with three topics.
- log4
- Appends log data with four topics.
- returndata_
acquire - Returns the data in the VM’s return buffer.
- returndata_
copy - Returns the segment of return buffer data beginning at
from
and continuing forlength
bytes. - returndata_
size - Returns the length of the data in the VM’s return buffer.
- revert
- Halts execution and reverts all changes to the state.
- revert_
data - Fills the return buffer with the given data and halts execution, reverting all state changes.
- selfdestruct
- Self-destructs the running contract, sending all its ether to a specified beneficiary address.
- storage_
load - Accesses the storage data at the specified key.
- storage_
store - Sets the storage data at the specified key.
- tx_
gas_ price - Returns the gas price of the currently executing call.
- tx_
origin - Returns the address of the original transaction sender.
- unsafe_
calldata_ copy - Executes callDataCopy, but does not check for overflow.
- unsafe_
code_ copy - Executes codeCopy, but does not check for overflow.
- unsafe_
external_ code_ copy - Executes externalCodeCopy, but does not check for overflow.
- unsafe_
returndata_ copy - Executes returnDataCopy, but does not check for overflow.