github OffchainLabs/stylus-sdk-rs v0.3.0
Stylus SDK 0.3.0

latest releases: v0.6.0, v0.4.3, v0.4.2...
14 months ago

This release introduces large improvements to the Stylus SDK. We've bumped the major version number due to minor backwards-incompatible changes. To adopt the latest version, edit your Cargo.toml as follows

stylus-sdk = "0.3.0"

Call Other Contracts

The sol_interface! macro and new Call type make writing calls to other contracts much easier.

sol_interface! {
    interface IService {
        function makePayment(address user) payable returns (string);
        function getConstant() pure returns (bytes32)
    }

    interface ITree {
        // other interface methods
    }
}

The above will define IService and ITree for calling the methods of the two contracts.

For example, IService will have a make_payment method that accepts an Address and returns a B256.

pub fn do_call(account: IService, user: Address) -> Result<String, Error> {
    let config = Call::new()
        .gas(evm::gas_left() / 2)       // limit to half the gas left
        .value(msg::value());           // set the callvalue

    account.make_payment(config, user)  // note the snake case
}

Observe the casing change. sol_interface! computes the selector based on the exact name passed in, which should almost always be CamelCase. For aesthetics, the rust functions will instead use snake_case.

Direct Delegate Call

Doing delegate calls have always been possible, but for added flexibility the new delegate_call method makes this easier in certain circumstances.

Additional methods exist for calls, static calls, and transfer eth too.

New reentrant Feature Flag

Most users won't want reentrancy. For this reason we've moved most methods behind the new reentrant flag. The SDK will always support them and provide protection via the Rust type system, but when disabled certain features become nicer.

In particular, various methods like RawCall::call that would be unsafe no longer are. Additionally, the new Call type will exist for making safe calls in any context.

Fully #[no_std]

The Stylus SDK is now fully #[no_std] compatible. You can opt-into this in your contract by adding

#![cfg_attr(not(feature = "export-abi"), no_main, no_std)]

100% docs.rs

The Stylus SDK is now fully documented on docs.rs. This includes all types, modules, and macros, including with code examples.

Don't miss a new stylus-sdk-rs release

NewReleases is sending notifications on new releases.