v4.0.0-beta
Pre-releaseVersion 4.0.0-beta
The focus of the first beta
release is to establish the stable ABI for the final 4.0.0
release. It means that whilst subsequent beta
releases may contain breaking contract
code changes, the ABI will remain the same so that any contract compiled and deployed
with 4.0.0-beta
continue to be compatible with all future 4.0.0
versions.
Compatibility
In order to build contracts which use ink! v4.0.0-beta
you need to use
cargo-contract
v2.0.0-beta
.
You can install it as follows:
cargo install cargo-contract --version 2.0.0-beta
You will also need to use a version of pallet-contracts
later than 265e3f1 (Nov 3, 2022)
in your node.
The v0.22.1
release of the substrate-contracts-node
is
compatible with the ink! 4.0.0-beta
release.
Breaking Changes
Constructors and Messages now return LangError
s
We have added a way to handle errors that are neither specific to a particular contract,
nor from the underlying execution environment (e.g pallet-contracts
). Instead these are
errors that may come from the smart contracting language itself.
For example, take the case where a contract message is called using an invalid selector.
This is not something a smart contract author should need to define as failure case, nor
is it something that the Contracts pallet needs to be aware of.
Previously, the contract execution would trap if an invalid selector was used, leaving
callers with no way to handle the error gracefully. This can now be handled with the help
of the newly added LangError
.
In short, this change means that all ink! messages and constructors now return a
Result<R, LangError>
, where R
is the original return type. Contract callers can
choose to handle the LangError
.
In order to make this error compatible with other languages we have also added a
lang_error
field to the metadata format. This will be the central registry of all the
different error variants which languages may want to emit in the future.
Related pull-requests:
Related discussions:
Random function removed
We had to remove ink_env::random
with #1442.
This function allowed contract developers getting random entropy.
There is unfortunately no way how this can be done safely enough
with built-in Substrate primitives on-chain currently. We're
following the recommendation of our auditors to remove it.
The alternative right now is to provide random entropy off-chain to
the contract, to use a random entropy oracle, or to have a chain-extension
that does this, in case the chain has a possibility to do so.
We hope to bring this function back in a future release of ink!, the
best hope right now is that it could come back with Sassafras, a block production
protocol for future versions of Polkadot.
Added
- Allow using
Result<Self, Error>
as a return type in constructors ‒ #1446 - Add
Mapping::take()
function allowing to get a value removing it from storage ‒ #1461
Changed
- Add support for language level errors (
LangError
) ‒ #1450 - Return
LangError
s from constructors ‒ #1504 - Update
scale-info
requirement to2.3
‒ #1467 - Merge
Mapping::insert(key, val)
andMapping::insert_return_size(key, val)
into one method - #1463
Removed
- Remove
ink_env::random
function ‒ #1442