- Introduce
#[callback_result]
annotation, which acts like#[callback]
except that it returnsResult<T, PromiseError>
to allow error handling. PR 554- Adds
#[callback_unwrap]
to replacecallback
- Adds
- mock: Update
method_names
field ofAddKeyWithFunctionCall
to aVec<String>
fromVec<Vec<u8>>
. PR 555- Method names were changed to be strings in
4.0.0-pre.2
but this one was missed
- Method names were changed to be strings in
- env: Update the register used for temporary
env
methods tou64::MAX - 2
from0
. PR 557.- When mixing using
sys
andenv
, reduces chance of collision for using0
- When mixing using
- Update
panic
andpanic_utf8
syscall signatures to indicate they do not return. PR 489 - Deprecate
env::panic
in favor ofenv::panic_str
. PR 492- This method now takes a
&str
as the bytes are enforced to be utf8 in the runtime. - Change is symmetric to
env::log_str
change in4.0.0-pre.1
- This method now takes a
- Removes
PublicKey
generic onenv
promise batch calls. Functions now just take a reference to thePublicKey
. PR 495 - fix: Public keys can no longer be borsh deserialized from invalid bytes. PR 502
- Adds
Hash
derive toPublicKey
- Adds
- Changes method name parameters from bytes (
Vec<u8>
and&[u8]
) to string equivalents for batch function call promises PR 515promise_batch_action_function_call
,Promise::function_call
,promise_batch_action_add_key_with_function_call
,Promise::add_access_key
, andPromise::add_access_key_with_nonce
are afffected.- Updates
promise_then
,promise_create
, andReceipt::FunctionCall
's method name to string equivalents from bytes PR 521. - Instead of
b"method_name"
just use"method_name"
, the bytes are enforced to be utf8 in the runtime.
- Fixes
#[ext_contract]
codegen function signatures to take anAccountId
instead of a genericToString
and converting unchecked toAccountId
. PR 518 - Fixes NFT contract standard
mint
function to not be in theNonFungibleTokenCore
trait. PR 525- If using the
mint
function from the code generated function on the contract, switch to call it on theNonFungibleToken
field of the contract (self.mint(..)
=>self.token.mint(..)
)
- If using the
- Fixes
nft_is_approved
method on contract standard to take&self
instead of movingself
. - Fixes
receiver_id
inmock::Receipt
toAccountId
from string. This is a change to the type added in4.0.0-pre.1
. PR 529 - Moves runtime syscalls to
near-sys
crate and includes new functions available PR 507
- Implements new
LazyOption
type underunstable
feature. Similar toLazy
but is optional to set a value. PR 444. - Move type aliases and core types to near-sdk to avoid coupling. PR 415.
- Implements new
Lazy
type under the newunstable
feature which is a lazily loaded storage value. PR 409. - fix(promise):
PromiseOrValue
now correctly setsshould_return
flag correctly on serialization. PR 407. - fix(tree_map): Correctly panic when range indices are exluded and
start > end
. PR 392. - Implement
FromStr
for json types to allow calling.parse()
to convert them. - expose
cur_block
andgenesis_config
fromRuntimeStandalone
to configure simulation tests. PR 390. - fix(simulator): failing with long chains. PR 385.
- Make block time configurable to sim contract tests. PR 378.
- Deprecate
env::log
in favour ofenv::log_str
. The logs assume that the bytes are utf8, so this will be a cleaner interface to use. PR 366. - Update syscall interface to no longer go through
BLOCKCHAIN_INTERFACE
. Instead usesnear_sdk::sys
which is under theunstable
feature flag if needed. PR 417. - Set up global allocator by default for WASM architectures. PR 429.
- This removes the re-export of
wee_alloc
because if this feature is enabled, the allocator will already be set. - Deprecates
setup_alloc!
macro as this will be setup by default, as long as thewee_alloc
feature is not specifically disabled. In this case, the allocator can be overriden to a custom one or set manually if intended.
- This removes the re-export of
- Update
TreeMap
iterator implementation to avoid unnecessary storage reads. PR 428. - Update
AccountId
to be a newtype with merged functionality fromValidAccountId
. PR 448- Removes
ValidAccountId
to avoid having multiple types for account IDs. - This type will have
ValidAccountId
's JSON (de)serialization and the borsh serialization will be equivalent to what it was previously
- Removes
- Initializes default for
BLOCKCHAIN_INTERFACE
to avoid requiring to initialize testing environment for tests that don't require custom blockchain interface configuration. PR 450- This default only affects outside of
wasm32
environments and is optional/backwards compatible
- This default only affects outside of
- Deprecates
env::block_index
and replaces it withenv::block_height
for more consistent naming. PR 474 - Updates internal NFT traits to not move the underlying type for methods. PR 475
- This should not be a breaking change if using the
impl
macros, only if implementing manually
- This should not be a breaking change if using the
- Makes
BLOCKCHAIN_INTERFACE
a concrete type and no longer exports it. PR 451- If for testing you need this mocked blockchain,
near_sdk::mock::with_mocked_blockchain
can be used near_sdk::env::take_blockchain_interface
is removed, as this interface is no longer optional- removes
BlockchainInterface
trait, as this interface is only used in mocked contexts now
- If for testing you need this mocked blockchain,
- Updates
Gas
type to be a newtype, which makes the API harder to misuse. PR 471- This also changes the JSON serialization of this type to a string, to avoid precision loss when deserializing in JavaScript
PublicKey
now utilizesBase58PublicKey
instead ofVec<u8>
directly PR 453. Usage ofBase58PublicKey
is deprecated- Expose
Receipt
and respectiveVmAction
s in mocked contexts through replacing with a local interface and types. PR 479
- Updated dependencies for
near-sdk
- Introduce trait
IntoStorageKey
and updating all persistent collections to take it instead ofVec<u8>
. It's a non-breaking change. - Introduce a macro derive
BorshStorageKey
that implementsIntoStorageKey
using borsh serialization. Example:
use near_sdk::BorshStorageKey;
#[derive(BorshSerialize, BorshStorageKey)]
enum StorageKey {
Records,
UniqueValues,
}
#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)]
pub struct StatusMessage {
pub records: LookupMap<String, String>,
pub unique_values: LookupSet<String>,
}
#[near_bindgen]
impl StatusMessage {
#[init]
pub fn new() -> Self {
Self {
records: LookupMap::new(StorageKey::Records),
unique_values: LookupSet::new(StorageKey::UniqueValues),
}
}
}
- Introduced
#[private]
method decorator, that verifiespredecessor_account_id() == current_account_id()
. NOTE: Usually, when a contract has to have a callback for a remote cross-contract call, this callback method should only be called by the contract itself. It's to avoid someone else calling it and messing the state. Pretty common pattern is to have an assert that validates that the direct caller (predecessor account ID) matches to the contract's account (current account ID). - Added how to build contracts with reproducible builds.
- Added
log!
macro to log a string from a contract similar toprintln!
macro. - Added
test_utils
mod fromnear_sdk
that contains a bunch of helper methods and structures, e.g.test_env
- simple test environment mod used internally.- Expanded
testing_env
to be able to pass promise results - Added
VMContextBuilder
to help construct aVMContext
for tests - Added
get_logs
method that returns current logs from the contract execution. - TEST_BREAKING
env::created_receipts
moved totest_utils::get_created_receipts
.env
shouldn't contain testing methods. - Updated a few examples to use
log!
macro
- Added
#[derive(PanicOnDefault)]
that automatically implementsDefault
trait that panics when called. This is helpful to prevent contracts from being initialized usingDefault
by removing boilerplate code. - Introduce
setup_alloc
macro that generates the same boilerplate as before, but also adds a #[cfg(target_arch = "wasm32")], which prevents the allocator from being used when the contract's main file is used in simulation testing. - Introduce
Base58CryptoHash
andCryptoHash
to represent32
bytes slice ofu8
. - Introduce
LazyOption
to keep a single large value with lazy deserialization. - BREAKING
#[init]
now checks that the state is not initialized. This is expected behavior. To ignore state check you can call#[init(ignore_state)]
- NOTE:
3.0.0
is not published, due to tag conflicts on thenear-sdk-rs
repo.
- Pinned version of
syn
crate to=1.0.57
, since1.0.58
introduced a breaking API change.
- Updated
status-message-collections
to useLookupMap
- BREAKING Updated
fungible-token
implementation to useLookupMap
. It changes storage layout.
- Introduce
LookupMap
andLookupSet
that are faster implementations ofUnorderedMap
andUnorderedSet
, but without support for iterators. Most read/lookup/write are done in 1 storage access instead of 2 or 3 forUnordered*
implementations. - BREAKING
Default
is removed fromnear_sdk::collections
to avoid implicit state conflicts. Collections should be initialized by explicitly specifying prefix usingnew
method. - BREAKING
TreeMap
implementation was updated to useLookupMap
. PreviousTreeMap
implementation was renamed toLegacyTreeMap
and was deprecated. It should only be used if the contract was already deployed and state has to be compatible with the previous implementation.
- Remove requirements for input args types to implement
serde::Serialize
and for return types to implementserde::Deserialize
.
- Bumped dependency version of
near-vm-logic
andnear-runtime-fees
to2.0.0
that changedVMLogic
interface.
- Re-export common crates to be reused directly from
near_sdk
. - Added
ValidAccountId
tojson_types
which validates the input string during deserialization to be a valid account ID. - Added
Debug
toBase58PublicKey
. - Bumped dependency version of
borsh
to0.7.0
. - Bumped dependency version of
near-vm-logic
andnear-runtime-fees
to1.0.0
. - Implemented Debug trait for Vector collection that can be enabled with
expensive-debug
feature.
- Use re-exported crate dependencies through
near_sdk
crate.
- Renamed
Map
toUnorderedMap
andSet
toUnorderedSet
to reflect that one cannot rely on the order of the elements in them. In this PR and in near#154
-
Added ordered tree implementation based on AVL, see
TreeMap
. near#154 -
Made module generated by
ext_contract
macro public, providing more flexibility for the usage: near#150
- Fungible token now requires from the users to transfer NEAR tokens to pay for the storage increase to prevent the contract from locking the users from operating on it. near#173
- Renaming method of fungible token
set_allowance
=>inc_allowance
. Addeddec_allowance
method. near#174 - Remove possibility to do self-transfer in fungible token. near#176
- Improving fungible token comments near#177
- Add account check to
get_balance
in fungible token near#175 - In fungible token remove account from storage if its balance is 0 near#179