Function ink_env::call::build_call[][src]

pub fn build_call<E>(
) -> CallBuilder<E, Unset<E::AccountId>, Unset<u64>, Unset<E::Balance>, Unset<ExecutionInput<EmptyArgumentList>>, Unset<ReturnType<()>>> where
    E: Environment

Returns a new CallBuilder to build up the parameters to a cross-contract call.

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: No Return Value

The below example shows calling of a message of another contract that does not return any value back to its caller. The called function …

  • has a selector equal to 0xDEADBEEF
  • is provided with 5000 units of gas for its execution
  • is provided with 10 units of transferred value for the 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
build_call::<DefaultEnvironment>()
    .callee(AccountId::from([0x42; 32]))
    .gas_limit(5000)
    .transferred_value(10)
    .exec_input(
        ExecutionInput::new(Selector::new([0xDE, 0xAD, 0xBE, 0xEF]))
            .push_arg(42)
            .push_arg(true)
            .push_arg(&[0x10u8; 32])
    )
    .returns::<()>()
    .fire()
    .unwrap();

Example 2: With Return Value

The below example shows calling of a message of another contract that does return a i32 value back to its caller. The called function …

  • has a selector equal to 0xDEADBEEF
  • is provided with 5000 units of gas for its execution
  • is provided with 10 units of transferred value for the 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_return_value: i32 = build_call::<DefaultEnvironment>()
    .callee(AccountId::from([0x42; 32]))
    .gas_limit(5000)
    .transferred_value(10)
    .exec_input(
        ExecutionInput::new(Selector::new([0xDE, 0xAD, 0xBE, 0xEF]))
            .push_arg(42)
            .push_arg(true)
            .push_arg(&[0x10; 32])
    )
    .returns::<ReturnType<i32>>()
    .fire()
    .unwrap();