0

Based on this example: https://docs.rs/ink/latest/ink/struct.EnvAccess.html#method.instantiate_contract

Im doing something similar:

#[ink(message)]
        pub fn new_multisig(&mut self, threshold: u8, owners_list: Vec<AccountId>, salt: Vec<u8>) {
            let multisig = build_create::<MultiSigRef>()
                .code_hash(self.multisig_codehash)
                .gas_limit(0)
                .endowment(0)
                .exec_input(
                    ExecutionInput::new(Selector::new(ink::selector_bytes!("new")))
                        .push_arg(threshold)
                        .push_arg(owners_list),
                )
                .salt_bytes(salt)
                .returns::<MultiSigRef>()
                .instantiate();

            self.env().emit_event(NewMultisig {
                multisig_address: multisig, //Here i need to get the address of the new contract
                threshold: threshold,
                owners_list: owners_list,
            });
        }

But i need to obtain the address of the instantiated contract. How can i do it?

1 Answer 1

5

You can use to_account_id method to obtain address of instantiated smart contract.

let contract_address = multisig.to_account_id();

Taking into account Luca's comment, the workable sample would be

use ink::ToAccountId;

let contract_address = multisig.to_account_id();
1
  • Hey! That worked, but i also needed to import the trait: use ink::ToAccountId;
    – Luca Auet
    Aug 1 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.