1

I need help with that code. Can anyone pls help me out ??

mod p{
        #[ink(storage)]
        pub struct Foobar {
            /// Stores a single `bool` value on the storage.
            value: bool,
        }


        impl Foobar {
            #[ink(constructor)]
            pub fn default() -> Self {
                Self::new(Default::default())
            }
        }


        #[ink_e2e::test]
        async fn default_works(mut client: ink_e2e::Client<C, E>) -> E2EResult<()> {
            // Given
            let constructor = FoobarRef::default();
            Ok(())
        }
}

what this line actually means. I have not created anything with the name FoobarRef but we are using it. and if FoobarRef is the same as Foobbar what is stored in a variable named constructor and how can I print it? let constructor = FoobarRef::default();

1 Answer 1

0

That FoobarRef is generated by ink! is a reference of the contract, it gives you the information about available methods (args, return types) of the contract you want to call.

With that line you can create an instance of your contract and interact with it in your test:

let contract_acc_id = client
                .instantiate("your_contract", &ink_e2e::alice(), **constructor**, 0, None)
                .await
                .expect("instantiate failed")
                .account_id;

See this example in the ink/examples repository and the Flipper example from the ink! Documentation

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.