pub fn create_program_bytes(
    code_id: CodeId,
    salt: impl AsRef<[u8]>,
    payload: impl AsRef<[u8]>,
    value: u128
) -> Result<(MessageId, ActorId)>
Expand description

Create a new program from the already existing on-chain code identified by CodeId.

The function returns an initial message identifier and a newly created program identifier.

The first argument is the code identifier (see CodeId for details). The second argument is an arbitrary byte sequence (also known as salt) that allows the creation of multiple programs from the same code. The third and last arguments are the initialization message’s payload and value to be transferred to the newly created program.

§Examples

Create a new program from the provided code identifier:

use gstd::{msg, prog, CodeId};

#[no_mangle]
extern "C" fn handle() {
    let code_id: CodeId = msg::load().expect("Unable to load");
    let (init_message_id, new_program_id) =
        prog::create_program_bytes(code_id, "salt", b"INIT", 0)
            .expect("Unable to create a program");
    msg::send_bytes(new_program_id, b"PING", 0).expect("Unable to send");
}