Since functions are not first-class objects in Solidity, is there any way to invoke a dynamically-determined function at runtime? e.g.

string fname = "Bar";

function Foo() {

function Bar() {
  // do something

Please respond regarding the feasibility and disregard security for the purpose of this question.


1 Answer 1


Yes, this is possible, but with some limitations.

You can call a function based on its ABI, so in your case


will call the Bar function of your contract. If the function takes an argument, you can add it to the call like so:

this.call(bytes4(sha3("Bar(int256)")), 42);

The only limitation to this is that you cannot return a value from this function, it only returns true, or false if it hits an exception.

You could use a global result variable, though.

In terms of security, it really depends on the context but be careful using msg.sender for authentication -- you may want to use callcode or delegatecall depending on your needs.


Not the answer you're looking for? Browse other questions tagged or ask your own question.