Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Blockchain by (4.1k points)

I am trying to make a contract have a function that is capable of calling functions of another contract. The key part of my goal is that the contract should not be able to be deployed without any import statements and will not know the name of the contract by default. In other words the user of this contract would input the called contracts data (i.e. address, name) as parameters. What is the best way to accomplish this?

1 Answer

0 votes
by (14.4k points)

As far as my understanding of your question allows me to perceive you are looking forward to deploying external contracts. However, you don’t seem to have details of how these contracts communicate. 

The best possible way to do this is to define their interfaces without importing the contract code. All you can do is define the function interfaces and leave the function definitions empty. 

You can do that by: 

contract WidgetInterface {

   function doSomething() returns(uint) {}

   function somethingElse() returns(bool isTrue) {}

}

You can use this interface contract to communicate with actual contracts: 

WidgetInterface wid = WidgetInterface(actualContractAddress);

You can also maintain a list of valid contracts that this interface successfully communicated with: 

if(!isAuthorized(actualContractAddress)) throw; 

Here, actualContractAddress is given by the sender and isAuthorized() is a function using which you can query an internal registry. 

Browse Categories

...