pub fn send<E: Encode>(
program: ActorId,
payload: E,
value: u128,
) -> Result<MessageId>
Expand description
Send a new message to the program or user.
Gear allows programs to communicate with each other and users via messages.
For example, the send
function allows sending such messages.
The first argument is the address of the target account (ActorId
). The
second argument is the encodable payload. The last argument is the value to
be transferred from the current program account to the message target
account.
Send transaction will be posted after processing is finished, similar to the
reply message reply
.
§Examples
Send a message to the arbitrary address:
use gstd::{msg, prelude::*, ActorId};
#[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),
};
// Receiver id is collected from bytes from 0 to 31
let id: [u8; 32] = core::array::from_fn(|i| i as u8);
msg::send(ActorId::new(id), payload, 0).expect("Unable to send");
}
§See also
reply
function sends a new message as a reply to the message that is currently being processed.MessageHandle::init
,MessageHandle::push
, andMessageHandle::commit
functions allow forming a message to send in parts.