What is a message in Ethereum?

Ethereum is a platform that is based on the blockchain and allows users to send and receive its native currency, ether.

Ethereum logo
Ethereum logo

What are message calls?

Message calls are a way to allow communication between contracts. Such communication could be calling other contracts or sending Ethereum to non-contract accounts. They are almost the same as transactions because they use gas, target, return data, source, and data payload.

What are smart contracts?

Smart contracts are stored on the Ethereum blockchain and are code-based. They perform certain functions when requirements are met. An example could be sending out funds after a deposit has occurred. It is the basis of most dApps across cryptocurrency platforms.

They can be written using several programming languages, such as JavaScript, but the most common is Solidity. It was created by Ethereum's co-founder and its first Chief Technology Officer (CTO).

How do message calls work?

To carry a message call, every transaction is nested or wrapped in a top-level message call, which could create more message calls. An example is where more messages need to be exchanged with calculations before finalizing a transaction.

The contract, in addition to its work, sets the amount of gas to be deducted from the outer message call before the remaining gas gets to the inner message call. This is known as an "out-of-gas" exception. An error value will be loaded onto the stack if this phenomenon happens to the inner message call instead of the outer message call. Only the gas that gets to the inner message call will be used.

In Solidity, the calling contract follows such situations by throwing an exception by default which leads to the exceptions bubbling up (emerging up the call stack).

Each time a function gets called, it will be attached to an instance of a working memory until the call ends. That instance is known as a stack frame, activation frame, or activation record.

This memory instance also gets the call payload, which is the function argument, via a separate memory area called the call data. The called contract will be able to return the data to a memory location in the caller’s memory, preallocated by the caller. The caller contract (function) always waits until it receives a reply from a called contract (function).

Contracts often have to be converted for machines to understand. This happens due to the Ethereum Virtual Machine (EVM). This is where smart contracts are deployed and executed. It is in every Ethereum node and over 140 operation codes (opcodes) can be carried out. They are, in essence, machine instructions in relation to tasks.

Message calls can go up to 1024 levels in depth. This means that they shouldn’t be used for iterating over an array or performing complex operations. If the function to be carried out is complex, loops are to be used. A limit also exists on the amount of gas that can be forwarded to a message call.

Along with ordinary message calls, special message calls exist called delegate calls and callcodes.

What are callcodes?

Callcodes are similar to ordinary message calls. The difference is that the code from the called contract (at the target address) is executed in the context of the calling contract (at the source address). In summary, the code executed acts as an important part of the calling contract.

What are delegate calls?

A delegate call also seems similar to a callcode, but keeps the variables (message sender, current address, message value, and account balance) unchanged.

Both calls allow contracts to load code from a different address at runtime, allowing one to import a remote contract as reusable library storage.

Free Resources