<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/advance-evm---opcodes-calling-and-low-level-instructions-c3vt0itmn" -->

---
title: Advance EVM - Opcodes, calling and low-level instructions
description: This post covers the fundamentals of the Ethereum Virtual Machine (EVM), focusing on low-level instructions, opcodes, encoding and decoding data, and calling...
canonical: https://daily.dev/posts/advance-evm---opcodes-calling-and-low-level-instructions-c3vt0itmn
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Advance EVM - Opcodes, calling and low-level instructions | daily.dev
og:description: This post covers the fundamentals of the Ethereum Virtual Machine (EVM), focusing on low-level instructions, opcodes, encoding and decoding data, and calling...
og:url: https://daily.dev/posts/advance-evm---opcodes-calling-and-low-level-instructions-c3vt0itmn
og:image: https://api.daily.dev/og/posts/c3vt0itmn.png
og:image:alt: Advance EVM - Opcodes, calling and low-level instructions
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Advance EVM - Opcodes, calling and low-level instructions

**[Ethereum BlockChain Development](https://daily.dev/sources/anuragiiitt)** · [@abiencodepacked](https://daily.dev/abiencodepacked) · 3 min read · 9 upvotes · 0 comments

## Summary

This post covers the fundamentals of the Ethereum Virtual Machine (EVM), focusing on low-level instructions, opcodes, encoding and decoding data, and calling functions using only the data field. It explains how transactions are compiled down to bytecode, the role of opcodes, and how to work with function selectors and signatures in Solidity.

## Content

# EVM compatible, opcodes and calling

- The EVM basically represents all the instructions a computer needs to be able to read.
- Any language that can compile down to bytecode with these opcodes is considered **EVM compatible**'

1. **Data in Transactions**:
    - When we send a transaction, it is `compiled` down to bytecode
    - The EVM processes this data to determine which function to call and what inputs to provide.

2. **Bytecode**:
   - When a contract is deployed, it is compiled into `bytecode understood by the EVM.` 
   - This `bytecode` represents exactly the `low level instructions` to make our contract happen.
   - This **bytecode consist of opcodes**

3. **Opcodes**:
   - Each opcode is a 2-character hexadecimal, represents some special instruction
   - This opcode reader is sometimes abstractly called the `EVM`   

4. **Encoding Data**:
    - Now, `ABI encoding will convert data into bytes`
    - Ex: **abi.encodePacked() || abi.encode()**

5. **Decoding data**:
    - Decoding is the process of taking the raw bytes and reconstructing the original data
    - Ex:  **abi.decode()**

6. **Low-Level call and staticcall**:
    1. **call** 
        - How we call functions to change the state variable of the blockchain
        ```js
        function stateChange(address _address) public {
            s_state[_address] = 12;
        }
        ```

    2. **staticcall**
       - This is how (at a low level) we do our "view" or "pure" function calls  
        ```js
        function getState() public view returns(uint256){
            return s_state;
        }
        ```

# Send TNX that call functions with just data field populated (EVM Signature Selector)

-  In order to call a function using only the data field of call, we need to encode:
    1. function name
    2. parameters we want to add

- Now each contract assigns each function a **`function ID/Method ID`**:
    
    1. **Function selector** is the first 4 bytes of the function signature
    2. **Function signature** a string that defines the function name & 
      parameters
      **Ex :  transfer(address,uint256)**

**Lets assume, we need to call `transfer(address,uint256)` function but by filling the data field!!!**

1. **getFunctionSelector**:

   ```js
    // By this method we will get function selector of the calling function.

    function getSelector() public pure returns (bytes4 selector) {
        selector = bytes4(keccak256(bytes("transfer(address,uint256)")));
    }
   ``` 

2. **call Transfer Function with selector**:
    
   - Will use **`abi.encodeWithSelector(bytes4 selector, args1, args2)`** 

    ```js
    // Here, using EVM cheatcodes we can directly call the transfer() function using data-field

    function callTransferData(address _address, uint256 _amount) public returns (bytes4 ,bool) {
        (bool success, bytes memory data) = address(this).call(
            abi.encodeWithSelector(getSelector(), _address,_amount)
        );
        return (bytes4(data), success);
    }
    ```

3. **`call Transfer Function with signature`**:

    - Will use **`abi.encodeWithSignature(string functSignature, args1, args2)`**

    ```js
    // Here, we will not use function selector. Rather, we will use function signature to call our transfer() function by populating data field.

    function callTransferDataSig(address _address, uint256 _amount) public returns (bytes4 ,bool) {
        (bool success, bytes memory data) = address(this).call(
            abi.encodeWithSignature("transfer(address,uint256)", _address,_amount)
        );
        return (bytes4(data), success);
    }
    ```
                               

**Note**: If there is anything wrong or if you want to share more concepts or if have any doubts. Pls comment below!!!

#ethereum #blockchain #smartcontract #web3 #evm #solidity #documentation

---

Tags: [#blockchain](https://daily.dev/tags/blockchain), [#ethereum](https://daily.dev/tags/ethereum), [#solidity](https://daily.dev/tags/solidity), [#evm](https://daily.dev/tags/evm)

[View this post on daily.dev](https://daily.dev/posts/advance-evm---opcodes-calling-and-low-level-instructions-c3vt0itmn)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"DiscussionForumPosting","mainEntityOfPage":"https://daily.dev/posts/advance-evm---opcodes-calling-and-low-level-instructions-c3vt0itmn","headline":"Advance EVM - Opcodes, calling and low-level instructions","text":"This post covers the fundamentals of the Ethereum Virtual Machine (EVM), focusing on low-level instructions, opcodes, encoding and decoding data, and calling functions using only the data field. It explains how transactions are compiled down to bytecode, the role of opcodes, and how to work with function selectors and signatures in Solidity.","url":"https://daily.dev/posts/advance-evm---opcodes-calling-and-low-level-instructions-c3vt0itmn","datePublished":"2025-01-11T19:18:03.578Z","dateModified":"2025-01-11T19:18:17.179Z","author":{"@type":"Person","name":"Anurag Shingare","url":"https://daily.dev/abiencodepacked","image":"https://media.daily.dev/image/upload/s--pLWLGNO0--/f_auto/v1735198145/avatars/avatar_HWlqjvZSl79rCUSk3LxVQ","description":"Web3 and Ethereum BlockChain | Nextjs | Solidity | Hardhat | Foundry | GenAI application |Typescript","interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"EndorseAction"},"userInteractionCount":30}},"image":"https://media.daily.dev/image/upload/s--n9c9wT_Y--/f_auto/v1736623083/posts/c3vt0itmn","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":9},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"isPartOf":{"@type":"WebPage","url":"https://daily.dev/squads/anuragiiitt","name":"Ethereum BlockChain Development"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Ethereum BlockChain Development","item":"https://daily.dev/squads/anuragiiitt"},{"@type":"ListItem","position":3,"name":"Advance EVM - Opcodes, calling and low-level instructions"}]}
```

