Expand description
Blockchain-specific methods available to the smart contract that allow to interact with NEAR runtime.
This is a wrapper around a low-level near_sys
. Unless you know what you are doing prefer using env::*
whenever possible. In case of cross-contract calls prefer using even higher-level API available
through callback_args
, callback_args_vec
, ext_contract
, Promise
, and PromiseOrValue
.
Functionsยง
- abort
- Aborts the current contract execution without a custom message.
To include a message, use
panic_str
. - account_
balance - The balance attached to the given account. This includes the attached_deposit that was attached to the transaction
- account_
locked_ balance - The balance locked for potential validator staking.
- alt_
bn128_ g1_ multiexp - Compute alt_bn128 g1 multiexp.
- alt_
bn128_ g1_ sum - Compute alt_bn128 g1 sum.
- alt_
bn128_ pairing_ check - Compute pairing check
- attached_
deposit - The balance that was attached to the call that will be immediately deposited before the contract execution starts
- block_
height - Returns the height of the block the transaction is being executed in.
- block_
index Deprecated - Current block index.
- block_
timestamp - Current block timestamp, i.e, number of non-leap-nanoseconds since January 1, 1970 0:00:00 UTC.
- block_
timestamp_ ms - Current block timestamp, i.e, number of non-leap-milliseconds since January 1, 1970 0:00:00 UTC.
- current_
account_ id - The id of the account that owns the current contract.
- ecrecover
- Recovers an ECDSA signer address from a 32-byte message
hash
and a correspondingsignature
along withv
recovery byte. - ed25519_
verify - Verifies signature of message using provided ED25519 Public Key
- epoch_
height - Current epoch height.
- input
- The input to the contract call serialized as bytes. If input is not provided returns
None
. - is_
valid_ account_ id - Returns
true
if the given account ID is valid andfalse
otherwise. - keccak256
- Hashes the random sequence of bytes using keccak256.
- keccak512
- Hashes the random sequence of bytes using keccak512.
- keccak256_
array - Hashes the bytes using the Keccak-256 hash function. This returns a 32 byte hash.
- keccak512_
array - Hashes the bytes using the Keccak-512 hash function. This returns a 64 byte hash.
- log
Deprecated - Log the UTF-8 encodable message.
- log_str
- Logs the string message message. This message is stored on chain.
- panic
Deprecated - Terminates the execution of the program with the UTF-8 encoded message.
panic_str
should be used as the bytes are required to be UTF-8 - panic_
str - Terminates the execution of the program with the UTF-8 encoded message.
- predecessor_
account_ id - The id of the account that was the previous contract in the chain of cross-contract calls.
If this is the first contract, it is equal to
signer_account_id
. - prepaid_
gas - The amount of gas attached to the call that can be used to pay for the gas fees.
- promise_
and - Creates a new promise which completes when time all promises passed as arguments complete.
- promise_
batch_ action_ add_ key_ allowance_ with_ function_ call - Attach promise action that adds a key with function call with specifi allowance to the NEAR promise index with the provided promise index.
- promise_
batch_ action_ add_ key_ with_ full_ access - Attach promise action that adds a full access key to the NEAR promise index with the provided promise index.
- promise_
batch_ action_ add_ key_ with_ function_ call Deprecated - Examples
- promise_
batch_ action_ create_ account - Attach a create account promise action to the NEAR promise index with the provided promise index.
- promise_
batch_ action_ delete_ account - Attach promise action that deletes the account to the NEAR promise index with the provided promise index.
- promise_
batch_ action_ delete_ key - Attach promise action that deletes the key to the NEAR promise index with the provided promise index.
- promise_
batch_ action_ deploy_ contract - Attach a deploy contract promise action to the NEAR promise index with the provided promise index.
- promise_
batch_ action_ function_ call - Attach a function call promise action to the NEAR promise index with the provided promise index.
- promise_
batch_ action_ function_ call_ weight - Attach a function call with specific gas weight promise action to the NEAR promise index with the provided promise index.
- promise_
batch_ action_ stake - Attach a stake promise action to the NEAR promise index with the provided promise index.
- promise_
batch_ action_ transfer - Attach a transfer promise action to the NEAR promise index with the provided promise index.
- promise_
batch_ create - Examples
- promise_
batch_ then - Examples
- promise_
create - Creates a promise that will execute a method on account with given arguments and attaches the given amount and gas.
- promise_
result - If the current function is invoked by a callback we can access the execution results of the promises that caused the callback.
- promise_
results_ count - If the current function is invoked by a callback we can access the execution results of the promises that caused the callback. This function returns the number of complete and incomplete callbacks.
- promise_
return - Consider the execution result of promise under
promise_idx
as execution result of this function. - promise_
then - Attaches the callback (which is a
near_primitives::action::FunctionCallAction
) that is executed after promise pointed bypromise_idx
is complete. - promise_
yield_ create - Creates a promise that will execute a method on the current account with given arguments. Writes a resumption token (data id) to the specified register. The callback method will execute after promise_yield_resume is called with the data id OR enough blocks have passed. The timeout length is specified as a protocol-level parameter yield_timeout_length_in_blocks = 200.
- promise_
yield_ resume - Accepts a resumption token
data_id
created by promise_yield_create on the local account.data
is a payload to be passed to the callback method as a promise input. Returns false if no promise yield with the specifieddata_id
is found. Returns true otherwise, guaranteeing that the callback method will be executed with a user-provided payload. - random_
seed - Returns the random seed from the current block. This 32 byte hash is based on the VRF value from the block. This value is not modified in any way each time this function is called within the same method/block.
- random_
seed_ array - Returns the random seed from the current block. This 32 byte hash is based on the VRF value from the block. This value is not modified in any way each time this function is called within the same method/block. Example of usage:
- read_
register - Reads the content of the
register_id
. If register is not used returnsNone
. - register_
len - Returns the size of the register. If register is not used returns
None
. - ripemd160_
array - Hashes the bytes using the RIPEMD-160 hash function. This returns a 20 byte hash.
- set_
blockchain_ interface - Replaces the current low-level blockchain interface accessible through
env::*
with another low-level blockchain interface with builtin functions of the NEAR runtime. In most cases you want to usetesting_env!
macro to set it. - setup_
panic_ hook - Setups panic hook to expose error info to the blockchain.
- sha256
- Hashes the random sequence of bytes using sha256.
- sha256_
array - Hashes the bytes using the SHA-256 hash function. This returns a 32 byte hash.
- signer_
account_ id - The id of the account that either signed the original transaction or issued the initial cross-contract call.
- signer_
account_ pk - The public key of the account that did the signing.
- state_
exists - Returns
true
if the contract state exists andfalse
otherwise. - state_
read - Load the state of the given object.
- state_
write - Writes the specified state to storage.
- storage_
byte_ cost - Price per 1 byte of storage from mainnet genesis config. TODO: will be using the host function when it will be available.
- storage_
get_ evicted - Reads the most recent value that was evicted with
storage_write
orstorage_remove
command. - storage_
has_ key - Checks if there is a key-value in the storage.
- storage_
read - Reads the value stored under the given key.
- storage_
remove - Removes the value stored under the given key.
If key-value existed returns
true
, otherwisefalse
. - storage_
usage - Current total storage usage of this smart contract that this account would be paying for.
- storage_
write - Writes key-value into storage.
If another key-value existed in the storage with the same key it returns
true
, otherwisefalse
. - used_
gas - The gas that was already burnt during the contract execution (cannot exceed
prepaid_gas
) - validator_
stake - For a given account return its current stake. If the account is not a validator, returns 0.
- validator_
total_ stake - Returns the total stake of validators in the current epoch.
- value_
return - Sets the blob of data as the return value of the contract.