3

As i have read at many resources, that these functions are low level functions. I want to know, should i use these methods to interact with already deployed contracts or not ?

4

They allow you to perform dynamic invocation (instead of static invocation) of a contract function.

This is similar to reflection in Java, where you execute a function using the function name string.

It is also similar to how you can call a function in interpreted languages like Python or Javascript.

For example:

def func(x):
   return x * 2
y = eval("func")(3)
print(y)

Or:

function func(x) {
    return x * 2;
}
const y = eval("func")(3);
console.log(y);

In a strong-typed language like Solidity, it means that the function which will be executed during runtime is not determined by the compiler, i.e., it is not hard-coded in the bytecode that the compiler generates.

These low level functions are useful in several different scenarios, here are some of them:

  • You're not sure about the type(s) of the return value(s)
  • You want to handle a failure without reverting

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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