Hey,
I have a few questions regarding Sophia.
-
Is it possible to create and deploy new contracts inside a function of another contract (e.g. create and deploy a Car contract in CarFactory contract function create_car(…))?
-
Is it possible to store only the address of a contract and when I want to call functions of it to cast it to its interface (e.g. ierc20: address, call transfer function IERC20(ierc20).transfer(…))?
Thanks
3 Likes
Hey @rwazqay,
- as @filip said, I think this is not possible right now
- what you can do is let the one contract have a mapping e.g.
map(address, Remotecontract)
, where you can add a remote contract like this
stateful entrypoint add_remotecontract(remotecontract : Remotecontract) =
put(state{ remotecontracts[Remotecontract.get_address()] = remotecontract})
Your remote contract will have to implement entrypoint get_address() = Contract.address
.
Sadly this is not optimal as address
type is ak_
so only references the account of that contract which can be misleading, but this allows you to call contracts via proxy by address.
3 Likes
Maybe you can have a look at the WORK IN PROGRESS governance contracts, where we have a registry of polls as separate contracts that follow a similar pattern as I described. aepp-governance/governance-contracts/contracts at master · aeternity/aepp-governance · GitHub
2 Likes
To do that, if it was possible, the first contract would need to have to know the code of the second contract. So why not include the functionality in the first contract then?
1 Like