Is there a way to deploy a smart contract from a contract? Typically we call these smart contracts ‘factory’ contracts.
Due to an explicit design decision, this is currently not possible. However, you can use a script as a workaround. In the future, there are plans to introduce a bundling feature, which should simplify the process of multi-transaction deployments and configurations.
Interesting, is there an example script with the deploy that I can reference doing something similar?
Hi there, @diyahir
There’s no way to deploy a smart contract from a sway script.
You must use the Typescript or Rust SDK.
I guess a follow-up question would be, is there a way of checking the byte-code or hash in the smart contract?
Something to the effect:
Parent → child1
add another child fn(child2)
require(child2 bytecode == child1 bytecode)
You want to check a contract’s bytecode from a sway or from the SDK?
Say I have a mapping for ‘valid’ contracts, within sway so that it is enforced at the contract level and not the script level
I would like to have in the function for example:
fn set_valid(contract: contractId)
require( hash(bytecode(contract)) == expected_hash)
valid_contracts_mapping.set(contract, true)
so that any contract added adheres to some expected logic, is is to achieve the same outcome of a factory contract in that the bytecode of the deployed contract is some known value
ignore pseudocode
Great question!
I think that’s possible, but maybe not implemented yet.
Let me get some help from the sway magicians and come back to you.
Did u guys end up adding this feature ? I want to deploy a NFT contract from my factory contract @calldelegation @naz3eh