pub fn send(
destination: ActorId,
payload: &[u8],
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 payload buffer. 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 with value to the arbitrary address (don’t repeat it in your program!):
use gcore::msg;
#[no_mangle]
extern "C" fn handle() {
// Receiver id is collected from bytes from 0 to 31
let id: [u8; 32] = core::array::from_fn(|i| i as u8);
msg::send(id.into(), b"HELLO", 42).expect("Unable to send");
}
§See also
reply
function sends a new message as a reply to the message that is currently being processed.send_init
,send_push
, andsend_commit
functions allow forming a message to send in parts.