2

I find myself needing to do two things with the Contracts pallet, which each raise a question:

  1. I want to call the instantiate_with_code extrinsic from another Rust function.

What is the correct way to build the code: Vec<u8> input? Is it as simple as passing my Wasm (compiled ink! contract), as a byte array?

  1. I want to call the call extrinsic from another Rust function.

How do I properly build the data: Vec<u8> input? The function in the smart contract is defined as:

fn set_admin(&mut self, account: AccountId)

I suspect I need to do something like: convert the selector value for set_admin from my metadata.json to a Vec<u8>, then convert the relevant AccountId to a Vec<u8> and append it. Is this the correct way to build data inputs for the Contracts pallet?

Are there any resources that define the correct format of the inputs for the Contracts pallet? I've searched but not been successful.

1 Answer 1

3

Question 1

Yes. The code is just the contents of the wasm file as emitted by the compiler.

Question 2

pallet-contracts doesn't concern itself with the data. It just passes it down to the contract as-is. From the point of view of paller-contracts there is just a call function that takes some input. That means it is up to the contract how to interpret that data. For contracts written in ink! you can look at the metadata on how to craft this input (as you already suggested). It would look like this in Rust:

("functionA".hash()[..3], paramA, paramB, paramC).encode()

encode() is the SCALE encoding. The first element of the tuple is the selector which you can take from the metadata.

2
  • Thanks. So if I'm instantiating a simple ink! contract, I can leave the data field empty?
    – jpataylor
    Jul 13, 2022 at 8:50
  • It can never be empty. You need at least the selector to select the correct constructor. Even if there is only one you need it AFAIK. Jul 14, 2022 at 12:56

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.