1

I am working on a project that requires a contract to be instantiated and retrieve address in a contract transaction. Here is an implementation done in Cosmwasm https://github.com/digitalnativeinc/standard-cosmwasm/blob/0d92518c512bede566852b10a5f5f065105641c3/contracts/vault_manager/src/contract.rs#L218

Is there any way I can implement it? I see a discussion at https://github.com/paritytech/ink/issues/6 but I do not see any further action regarding this.

1
  • Can this be in smart contract code. I mean It is obvious that UI supports that, but where is the code to generate that like solidity? Commented Aug 5, 2022 at 3:54

3 Answers 3

1
Uploading your contract on the blockchain with `contract-pallet` has two phases:
- Deploy - deploys source code to the blockchain. After deploying, the network uses the hash of the source code as an identifier for future instantiation of the contract. Now anyone can instantiate the contract by source code hash.
- Instantiation - creates the instance of the contract on the blockchain that uses source code by its hash. After that, anyone can interact with the contract.

Copy/paste this text from doc.

If you want to instantiate the contract, first it should be deployed to the network by someone, and you need to know the code hash of the contract(logic layer).

After you have several options on how to instantiate it. You can import the source of the contract into your project like here. And after, instantiate it via auto generated Ref type like here.

Another solution is to use raw environment method or to use create_builder. But it requires more data from you like selector of constructor and so on.

In the future OpenBrush and ink! will provide a more user-friendly way how to instantiate it without the import of the source code=)

1
  • Thank you. This explains everything. Looking forward to see in openbrush example. Commented Aug 8, 2022 at 5:31
0

ink! Smart Contracts are deployed into a code-bundle, which is addressed by its hash. The Contract can then be instantiated from that hash.

The Substrate Contracts UI provides a page for that.

1
  • No thank you. I need smart contract code example. Commented Aug 8, 2022 at 5:28
0

Seems you are trying to make a cross contract call.

You can look at this question to take a cue on the best way to achieve this.

You can also make a low-level cross contract call using the build_call and providing a selector.

3
  • so does this mean I can generate one or not? Commented Aug 5, 2022 at 3:55
  • I am not really sure what you mean by generate one or not? what do you want to generate?
    – dharjeezy
    Commented Aug 5, 2022 at 15:09
  • No thank you. there is already a guy who answered. Commented Aug 8, 2022 at 5:36

Your Answer

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

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