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

# eth_call | Polygon

> Polygon API method that enables instant execution of a new message call without requiring the creation of a transaction on the blockchain.

Polygon API method that enables instant execution of a new message call without requiring the creation of a transaction on the blockchain. This can be useful for testing and debugging by simulating transfers or smart contract transactions and retrieving data from the blockchain.

<Note>
  **Disclaimer**

  The interactive example in this page uses `eth_call` to call the `lpToken` method from [SushiSwap MiniChefV2 smart contract on Polygon](https://polygonscan.com/address/0x0769fd68dfb93167989c6f7254cd0d766fb2841f#code). It returns the address of the liquidity pool at the index specified in the data. In this case, the input is 1, and it returns the [current address for the USDC-WETH pool for SushiSwap](https://polygonscan.com/address/0x34965ba0ac2451a34a0471f04cca3f990b8dea27) on Polygon.
</Note>

<Note>
  When called against a block older than the latest \~128 blocks, this method is treated as an archive request (2 RUs instead of 1 RU). See [request units](/docs/request-units#archive-state-methods).
</Note>

<Check>
  **Get your own node endpoint today**

  [Start for free](https://console.chainstack.com/) and get your app to production levels immediately. No credit card required.

  You can sign up with your GitHub, X, Google, or Microsoft account.
</Check>

## Parameters

* `object` — the transaction call object:

  * `from` — (optional) the string of the address used to send the transaction.
  * `to` — the string of the address to which the transaction is directed, a wallet, or a smart contract.
  * `gas` — (optional) the maximum amount of gas that can be used by the transaction.
  * `gasprice` — (optional) the amount of gas price the sender is willing to pay for each gas unit in [Wei](https://ethereum.org/en/developers/docs/intro-to-ether/#denominations).
  * `value` — (optional) the value sent with this transaction, encoded as hexadecimal.
  * `data` — (optional) additional data to be sent with the call, usually used to invoke functions from smart contracts as a string of the hash of the method signature and encoded parameters. See the [Ethereum Contract ABI](https://solidity.readthedocs.io/en/latest/abi-spec.html).
* `quantity or tag` — the integer of a block encoded as hexadecimal or the string with:

  * `latest` — the most recent block in the blockchain and the current state of the blockchain at the most recent block
  * `earliest` — the earliest available or genesis block
  * `pending` — the pending state and transactions block. The current state of transactions that have been broadcast to the network but have not yet been included in a block.

<Note>
  See the [default block parameter](https://eth.wiki/json-rpc/API#the-default-block-parameter).
</Note>

## Response

* `data` — the result of executing the specified call on the Ethereum Virtual Machine (EVM), encoded as a hexadecimal string.

## `eth_call` code examples

The following code snippets provide a clear demonstration of how to simulate a standard MATIC transfer between two accounts. Note that when using `eth_call` to simulate a transfer or a smart contract transaction, the sender account must have a sufficient balance to cover the associated gas fee.

<CodeGroup>
  ```javascript web3.js theme={"system"}
  const Web3 = require("web3");
  const NODE_URL = "CHAINSTACK_NODE_URL";
  const web3 = new Web3(NODE_URL);

  async function simulateTransfer() {
      try {
          // Define the accounts to transfer between
          const fromAddress = "0xAd80f9fcc2a315aBB6007F6fd6cCEC74C1168b9a";
          const toAddress = "0x19e7e376e7c213b7e7e7e46cc70a5dd086daff2a";

          // Define the value to transfer (converted to Wei)
          const value = web3.utils.toWei("100", "ether");

          // Build transaction object
          const transactionObject = {
              from: fromAddress,
              to: toAddress,
              gas: 21000, // 21000 is the standard for a regular tranfer
              value: value,
              data: ""
          }

          // Use eth_call to simulate the transfer on the latest block
          const result = await web3.eth.call({
              transactionObject
          }, "latest");

          console.log(`Transaction hash: ${result}`);
      } catch (error) {
          console.error(`Error: ${error.message}`);
      }
  }

  simulateTransfer();
  ```

  ```javascript ethers.js theme={"system"}
  const ethers = require('ethers');
  const NODE_URL = "CHAINSTACK_NODE_URL";
  const provider = new ethers.JsonRpcProvider(NODE_URL);

  const simulateTransfer = async () => {
    try {    
      // Define the accounts to transfer between
      const fromAddress = "0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5";
      const toAddress = "0x19e7e376e7c213b7e7e7e46cc70a5dd086daff2a";

      // Define the value to transfer
      const value = ethers.parseEther("1");

      // Build transaction object
      const transactionObject = {
          from: fromAddress,
          to: toAddress,
          gasLimit: ethers.toQuantity(21000),
          value: value
      }

      // Use eth_call to simulate the transfer on the latest block
      const result = await provider.call(transactionObject);
      console.log(`Result: ${result}`);

    } catch (error) {
      console.error(`Error: ${error.message}`);

    }
  }

  simulateTransfer();
  ```

  ```python web3.py theme={"system"}
  from web3 import Web3  
  node_url = "CHAINSTACK_NODE_URL"

  web3 = Web3(Web3.HTTPProvider(node_url)) 

  # Define the accounts to transfer between
  from_address = web3.to_checksum_address('0xAd80f9fcc2a315aBB6007F6fd6cCEC74C1168b9a')
  to_address = web3.to_checksum_address('0x19e7e376e7c213b7e7e7e46cc70a5dd086daff2a')

  # Define the value to transfer (in Ether)
  value = web3.to_wei(1, 'ether')

  # Build the transaction object
  transaction = {
      'from': from_address,
      'to': to_address,
      'gas': 21000,  # 21000 is the standard for a regular transfer
      'value': value,
      'data': '',
  }

  # Use eth_call to simulate the transfer
  result = web3.eth.call(transaction, 'latest')
  print(result)
  ```
</CodeGroup>

Executing this code will produce a return value of `0x`, indicating a successful transaction. This implies that the transaction will be executed without any errors when the code is used to send the transaction.

## Use case

A common use case for `eth_call` is calling smart contract functions. For example, interact with an ERC-20 token smart contract deployed on the Polygon network and retrieve the balance of a specific account.

The following code uses the web3.js library to call the `balanceOf` function of the [APE token smart contract](https://polygonscan.com/token/0xB7b31a6BC18e48888545CE79e83E06003bE70930#code) on the Polygon network.

```javascript index.js theme={"system"}
const Web3 = require("web3");
const NODE_URL = "CHAINSTACK_NODE_URL";
const web3 = new Web3(NODE_URL);


// Contract address and ABI for the token
const CONTRACT_ADDRESS = "0xB7b31a6BC18e48888545CE79e83E06003bE70930";
const ABI = [
  {
    "constant": true,
    "inputs": [
      {
        "name": "_owner",
        "type": "address"
      }
    ],
    "name": "balanceOf",
    "outputs": [
      {
        "name": "balance",
        "type": "uint256"
      }
    ],
    "payable": false,
    "stateMutability": "view",
    "type": "function"
  }
];

// Asynchronously fetches the balance of an account for the given address
async function getAccountBalance(address) {
  try {
    // Create a new contract instance
    const contract = new web3.eth.Contract(ABI, CONTRACT_ADDRESS);

    // Call the balanceOf function to retrieve the account balance in wei using eth_call
    const balanceInWei = await contract.methods.balanceOf(address).call();

    // Convert the balance from wei to ethers
    const balanceInEth = web3.utils.fromWei(balanceInWei, "ether");

    // Log the account balance in ethers to the console
    console.log(`The account balance for address ${address} is: ${balanceInEth} APE`);
    
  } catch (error) {
    console.error("Error occurred while fetching account balance:", error);
  }
}

// Call the getAccountBalance function with a sample account address
getAccountBalance("0xf07f7da6381fa11a4b47ea31164828a1bb9cdeaf");
```

The `getAccountBalance` function is called with the address of the account whose balance we want to retrieve. This function creates a new contract instance, calls the `balanceOf` function of the smart contract with the provided address, and retrieves the account balance in Wei. The balance is then converted to the ethers unit using the `fromWei` function of the `web3.utils` object.

Finally, the account balance is printed to the console for easy viewing.


## OpenAPI

````yaml /openapi/polygon_node_api/execute_transactions/eth_call.json POST /a9bca2f0f84b54086ceebe590316fff3
openapi: 3.0.0
info:
  title: eth_call example
  version: 1.0.0
  description: This is an API example for eth_call.
servers:
  - url: https://nd-828-700-214.p2pify.com
security: []
paths:
  /a9bca2f0f84b54086ceebe590316fff3:
    post:
      tags:
        - upload
      summary: eth_call
      operationId: ethCall
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                jsonrpc:
                  type: string
                  default: '2.0'
                method:
                  type: string
                  default: eth_call
                id:
                  type: integer
                  default: 1
                params:
                  type: array
                  items:
                    anyOf:
                      - type: object
                        properties:
                          to:
                            type: string
                            default: '0x0769fd68dFb93167989C6f7254cd0D766Fb2841F'
                          data:
                            type: string
                            default: >-
                              0x78ed5d1f0000000000000000000000000000000000000000000000000000000000000001
                      - type: string
                        default: latest
                  default:
                    - to: '0x0769fd68dFb93167989C6f7254cd0D766Fb2841F'
                      data: >-
                        0x78ed5d1f0000000000000000000000000000000000000000000000000000000000000001
                    - latest
      responses:
        '200':
          description: The call information
          content:
            application/json:
              schema:
                type: object
                properties:
                  jsonrpc:
                    type: string
                  id:
                    type: integer
                  result:
                    type: object

````