Function gstd::msg::send_bytes
source · pub fn send_bytes<T: AsRef<[u8]>>(
program: ActorId,
payload: T,
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_bytes
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_bytes
.
§Examples
Send a message with value to the arbitrary address (don’t repeat it in your program!):
use gstd::{msg, ActorId};
#[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_bytes(ActorId::new(id), b"HELLO", 42).expect("Unable to send");
}
§See also
reply_bytes
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.