Closed tk-o closed 2 years ago
As far as I know, putcode is deprecated, as determined by the chain, so there is no way you can just upload wasmcode without instantiating the contract. redspot's putcode function is just for compatibility with older versions of the chain (which had putcode method)
The new version of the chain has only instantiateWithCode (which contains both putcode and instantiate) and no separate putcode.
@tk-o parity does not think they need put_code, though I think it's a bad idea. Look at this issue: https://github.com/paritytech/substrate/issues/8671
I try to convince them to recover put_code, but they do not agree.
So at here, the way in practice is first deploying a useless contract, let the code already on the chain, then you contract which uses the deployed contract can do the normal thing.
parity thinks the 3rd party can hide the process, but we do not think of a good idea to do this. For initing a contract may need some parameters, we can neither identify whether the developer wants to instantiate the contract or just need code, nor can we guess what parameters the developer needs to instantiate the contract.
So at now, developer needs to init the contract by himself to put the code on the chain.
Thanks for all the details, folks 🤝
I'll be looking into CosmWasm now to see if it's more approachable tech for dApp developers.
The solution for this problem is to not instantiate (B) from within (A). You embed the contract address of (B) in (A) and assume it to be instantiated. Contract addresses are deterministic and guarantee to be derived from a specific code hash. So you can even instantiate (B) after instantiating (A).
I've been playing with a use-case where a smart contract (A) needs to instantiate another smart contract (B). I was not able to have it done using
ContractFactory
.Deploying A requires a code hash to B, but
ContractFactory.#putCode
is only called from inside theContractFactory.deploy
which also instantiates the contract (I don't need it to happen for B).It would be great if
#putCode
was public, so there is an explicit way to upload a WASM on-chain without having it instantiated.What do you think?
Context
From what I see:
ContractFactory.deploy
does 2 thingsI understand that I need to call
ContractFactory.#putCode
, but it's a private method, so how do I do that?Originally posted by @tk-o in https://github.com/paritytech/ink/issues/875#issuecomment-905901177