I’m stuck, so every answer is appreciated.
What I want to achieve is to call an external function from dynamically created smart contracts as different owners, but restrict to call that function direct in a smart contract. Is it possible ?
I’m stuck, so every answer is appreciated.
What I want to achieve is to call an external function from dynamically created smart contracts as different owners, but restrict to call that function direct in a smart contract. Is it possible ?
It is possible, the only requirement is that you know the contract's address upfront; there are two approaches you can take for this:
using address(contractAddresS).call() - more info here
(bool burned,) = address( yourContract).call( abi.encodeWithSignature( "burn(address,uint256,uint256)", address( this), burnedId, amountToBurn) ); or using an interface of the contract:
interface YourExternalContract { function burn( address from, uint256 id, uint256 amount) external; } contract fooContract { function burnExternalToken( address from, uint256 id, uint256 amount, address externalContract) external { contract = YourExternalContract( externalContract); require( contract.burn( from, id, amount), "burn failed"); } } EDIT_EDIT_EDIT_EDIT
How about this: You use Clones from openzeppelin and then grant a role to the new contract in the same transaction; Look at this implementation of a clone contract
in this part you just need to add the "add role for the new contract code":
function genesis( string calldata title, Stream.Member[] calldata members) external returns (address) { address payable clone = payable( Clones.clone( implementation)); Stream s = Stream( clone); //refactor this to add "calleable by XXX" in your contract C s.initialize( members); emit ContractDeployed( msg.sender, clone, title); return clone; }