Web3 & MetaMask - Bubble plugin
Get PluginAll our plugins
  • Overview
  • Quick Start Example
  • Elements details
    • Web3 & MetaMask
      • Connect To MetaMask
      • Disconnect MetaMask
      • Send token With MetaMask
      • Get Balance of a Token
      • Get Balance of Multiple Tokens
      • Get Token Symbol
      • Sign
      • Check signature
      • Sign Typed Data
      • Check signature-Typed Data
      • Smart Contract - Read
        • Example - CAKE/BUSD rate on Pancaksewap
      • Smart Contract - Write
        • Example - Write a function
      • Trigger Switch Chain
      • Approve - Set Allowance
      • Revoke Allowance
      • Deploy Contract
      • Add Chain to MetaMask
      • Get NFT Metadata
      • Check NFT Balance
      • Smart Contract - Read
      • Smart Contract - Write
    • Web3 Utils
      • Get Transaction confirmations
      • Get Transaction Details
      • To Wei
      • From Wei
      • Add Token to MetaMask
      • Get ENS data
      • Get ENS Domain from Address
  • Use with other Wallets & Plugins
  • Sign up a user with signature
  • How to use on Mobile
Powered by GitBook
On this page
  • Parameters
  • Events
  • States
  • Demo
  • More about ABI
  • - Where to get the ABI
  • - ABI Syntax
  • Find all contract functions and parameters
  1. Elements details
  2. Web3 & MetaMask

Smart Contract - Read

Read data from a smart contract using its Read functions

PreviousCheck signature-Typed DataNextExample - CAKE/BUSD rate on Pancaksewap

Last updated 2 years ago

Parameters

Parameter name
Type
Description

Contract address

Text

Smart Contract Address

ABI

Text

Action name

Text

Optional parameters

In some cases to read a contract you need to indicate additional parameters

Parameter 1 - Parameter 3

Text

All are optional, if the contract requires 1 parameter, for example a wallet address, set it in the Parameter 1 and leave the rest empty

Events

Event name
Description

Contract read

Triggered when the reading data is available in the state.

Unknown Error Occurred

Triggers when reading a contract and something went wrong

States

State name
Type
Description

Contract Read - Result

Text

All results will be converted to text, for example if it is JSON, you will have to parse it using regex or if it is number you will have to convert it to number type

This demo works on BSC chain, it reads the Pancakeswap contract to get the swap price for CAKE to BUSD

When reading a contract, make sure you are connected to the same chain as where the smart contract is.

More about ABI

- Where to get the ABI

What if Contract is not verified and I can't see the ABI?

In some cases, when the smart contract was deployed but not verified by developer, the Contract section won't contain the ABI. There is a workournd for this, most of the time you will need some basic function from the smart contract and usually the contract was deployed under some standards. For example, if you have an NFT contract of ERC721 type then your contract will have similar (if not exact) the same ABI as a standard ERC721 contract type. What it means is that you can just copy the ABI from other ERC721 contract type and use it for your contract. It will work if the function name you need is the same as in other contracts (for example: balanceOf) Otherwise ask for the developer to either verify the contract or give you the ABI directly.

- ABI Syntax

Simply copy and paste it, do not make changes, make sure the double quotes are of standard type and it is not auto replaced by single quote or other types.

Example of a correct ABI
[{"constant":true,"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"}]

OR in formatted form

[{
        "constant": true,
        "inputs": [
            {
                "internalType": "address",
                "name": "owner",
                "type": "address"
            }
        ],
        "name": "balanceOf",
        "outputs": [
            {
                "internalType": "uint256",
                "name": "",
                "type": "uint256"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    },{
        "constant": true,
        "inputs": [],
        "name": "isOwner",
        "outputs": [
            {
                "internalType": "bool",
                "name": "",
                "type": "bool"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    }
]

Find all contract functions and parameters

Similar to how we found the Contract ABI demonstrated above, while you are in the Contract section on etherscan, open the Read Contract You will see a list of all functions available to read from the contract. Each can be opened and see what parameters it needs if any.

If a parameter is an array type with multiple data, set it all in one parameter by indicating the square brackets, make sure to use double quotes when it is string type. For example: Parameter 1:

["0x10ed43c718714eb63d5aa57b78b54704e256024e",true,1]

Contract ABI. After contract deployment the ABI doesn't change, therefore it can be saved in your database and get it from there when needed. More about ABI see

This is the function name from the contract that you want to use. Case sensitive, make sure it is exactly as in the contract, for example: isOwner or balanceOf See where to find all contract functions and its parameters

The easiest way is to go directly to (or other blockchain scanner depends on where the contract is deployed) and search for it using the contract address. Then go to Contract section and search for the Contract ABI and just copy all of that text that you see in the ABI section.

Demo
etherscan
lower on this page
here
Example