pub fn send_from_reservation<E: Encode>(
    id: ReservationId,
    program: ActorId,
    payload: E,
    value: u128
) -> Result<MessageId>
Expand description

Same as send, but it spends gas from a reservation instead of borrowing it from the gas limit provided with the incoming message.

The first argument is the reservation identifier ReservationId obtained by calling the corresponding API. The second argument is the address of the target account (ActorId). The third argument is the encodable payload. Finally, the last argument is the value to be transferred from the current program account to the message target account.

§Examples

Send a message to the sender’s address:

use gstd::{msg, prelude::*, ReservationId};

#[derive(Encode)]
#[codec(crate = gstd::codec)]
struct Output {
    a: i32,
    b: Option<bool>,
}

#[no_mangle]
extern "C" fn handle() {
    let payload = Output {
        a: 42,
        b: Some(true),
    };
    // Reserve 5 million of gas for 100 blocks
    let reservation_id = ReservationId::reserve(5_000_000, 100).expect("Unable to reserve");
    // Receiver id is the message source
    let actor_id = msg::source();

    msg::send_from_reservation(reservation_id, actor_id, payload, 0).expect("Unable to send");
}

§See also