Function build_create

Source
pub fn build_create<ContractRef>() -> CreateBuilder<<ContractRef as ContractEnv>::Env, ContractRef, Set<LimitParamsV2>, Unset<ExecutionInput<EmptyArgumentList<DefaultAbi>, DefaultAbi>>, Unset<ReturnType<()>>, DefaultAbi>
where ContractRef: ContractEnv,
Expand description

Returns a new CreateBuilder to build up the parameters to a cross-contract instantiation that uses the “default” ABI for calls for the ink! project.

§Note

The “default” ABI for calls is “ink”, unless the ABI is set to “sol” in the ink! project’s manifest file (i.e. Cargo.toml).

§Example

Note: The shown examples panic because there is currently no cross-calling support in the off-chain testing environment. However, this code should work fine in on-chain environments.

§Example 1: Returns Address of Instantiated Contract

The below example shows instantiation of contract of type MyContract.

The used constructor:

  • has a selector equal to 0xDEADBEEF
  • is provided with 4000 units of gas for its execution
  • is provided with 25 units of transferred value for the new contract instance
  • receives the following arguments in order 1. an i32 with value 42 2. a bool with value true 3. an array of 32 u8 with value 0x10
let my_contract: MyContractRef = build_create::<MyContractRef>()
    .code_hash(ink::H256::from([0x42; 32]))
    .endowment(25.into())
    .exec_input(
        ExecutionInput::new(Selector::new(ink::selector_bytes!("my_constructor")))
            .push_arg(42)
            .push_arg(true)
            .push_arg(&[0x10u8; 32]),
    )
    .salt_bytes(Some([1u8; 32]))
    .returns::<MyContractRef>()
    .instantiate();

§Example 2: Handles Result from Fallible Constructor

let my_contract: MyContractRef = build_create::<MyContractRef>()
    .code_hash(ink::H256::from([0x42; 32]))
    .endowment(25.into())
    .exec_input(
        ExecutionInput::new(Selector::new(ink::selector_bytes!("my_constructor")))
            .push_arg(42)
            .push_arg(true)
            .push_arg(&[0x10u8; 32]),
    )
    .salt_bytes(Some([1u8; 32]))
    .returns::<Result<MyContractRef, ConstructorError>>()
    .instantiate()
    .expect("Constructor should have executed successfully.");