1

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 ?

1

1 Answer 1

1

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; } 
10
  • Hi! Thank you for reply, but this is not exactly what i'm looking for.What I would like to obtain is the ability to make a call by any tx.origin/msg.sender. there are contracts A - B - C, do you know how to create restrictions on functions in contract C while you make a "call" from contract B, which will have a variable contract address ? So you can't call direct a function in contract C, but You can call it from different smart contract with variable contract address. Commented Dec 7, 2022 at 8:37
  • maybe you can use this: Access role implementation; You can restrict who can call which function ^.^ ethereum.stackexchange.com/a/140002/99976 Commented Dec 7, 2022 at 8:43
  • You;re basically granting roles to external contracts and limiting call functions to only addresses with the role; you can remove roles as well so its quite flexible; Commented Dec 7, 2022 at 8:45
  • Still it’s not the case, because I will not know the address of the contract because it’s dynamically created, so dynamically created smart contract will call contract C, so You can’t hardcode it or give access role. The users will generate tickets which are new smart contracts and those new smart contracts need to be able to call contract C, but you can’t call a function direct in contract C. I’m thinking about some kind of modifier here .. but not sure. Commented Dec 7, 2022 at 8:51
  • aah I get it! If you use Clones from Openzeppelin, you can deploy a clone of a previously deployed contract and add a role in the same transaction Commented Dec 7, 2022 at 9:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.