128 votes

What is an ABI and why is it needed to interact with contracts?

The ABI, Application Binary Interface, is basically how you call functions in a contract and get data back. An ABI determines such details as how functions are called and in which binary format ...
eth's user avatar
  • 85.7k
71 votes
Accepted

How to call a contract method using the eth_call JSON-RPC API

Summary Your original contract code would not work correctly until I added a constant to the function definition to indicate that this function does not modify the blockchain. I had to use the method ...
BokkyPooBah's user avatar
  • 40.3k
48 votes
Accepted

How do you get a json file (ABI) from a known contract address?

The JSON is called an ABI. You do need the source code, as you have, and one way to get the ABI is to paste it in Remix IDE, compile it, and then click the 'ABI' button to copy the ABI into your ...
eth's user avatar
  • 85.7k
44 votes
Accepted

What is calldata?

Here is an example from What is an ABI and why is it needed to interact with contracts? contract Foo { function baz(uint32 x, bool y) returns (bool r) { r = x > 32 || y; } } If we wanted to call ...
eth's user avatar
  • 85.7k
41 votes
Accepted

Why are there two methods encoding arguments? "abi.encode" and "abi.encodePacked"

I'd recommend to use 4 at all times if possible. It is easy to remember and write. The behavior is that it will revert the whole transaction if the call fails, which is the most reasonable alternative ...
Ismael's user avatar
  • 30.6k
33 votes
Accepted

Getting ABI data for ERC20 tokens programatically with Web3

Thank you K.Fichter for the help, I just want to fully clarify the answer for anyone else who may run into this issue. Let's say you want to get the balance of a token at an Ethereum Address. Using ...
Shawn Tabrizi's user avatar
25 votes
Accepted

How to find solidity code for a contract address

Mainly due to optimizations carried out when the source code is compiled it's not feasible to get the source code from the bytecode/opcode itself. Refer this question. Compilation back to the ...
Achala Dissanayake's user avatar
24 votes

What is an ABI and why is it needed to interact with contracts?

Contract Defintion: Formal definition in high-level code (e.g. solidity). Compiled Contract: The contract converted to byte-code to run on the Ethereum Virtual Machine (EVM), adhering to the ...
Lee's user avatar
  • 8,548
24 votes

what does "Warning: This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" mean

It means that now you need to change your code to: uint256 _unixTimestamp; uint256 _timeExpired; bytes32 output = keccak256( abi.encodePacked(msg.sender, _unixTimestamp, _timeExpired) );
rstormsf's user avatar
  • 4,337
24 votes
Accepted

What does the function "abi.encodeWithSelector(bytes4 selector, ...) returns (bytes memory)" do exactly?

A function selector is the first 4 bytes in the hash of the function's prototype. A function prototype is defined as the function's name and its argument types by order. It allows you, for example, to ...
goodvibration's user avatar
23 votes

What does Solidity's "call" function mean?

Solidity's call is a low-level interface for sending a message to a contract. It returns false if the subcall encounters an exception, otherwise it returns true. There is no notion of a legal call, ...
eth's user avatar
  • 85.7k
22 votes
Accepted

Web3.js Get Contract Abi Knowing Only Contract Address

a) you know the source code of smart-contract programmatically: see the link to gist from Ivan's answer manually: with Remix b) you don't know the source code but smart-contract was verified in one of ...
Victor Baranov's user avatar
22 votes
Accepted

Trouble with web3.eth.Contract, ABI usage with Typescript

you can also do import { AbiItem } from 'web3-utils' import Abi from './abi.json' new web3.eth.Contract(Abi as AbiItem[], contractAddress)
yangli-io's user avatar
  • 423
22 votes
Accepted

How to use address.call{}() in Solidity

After doing some research, I finally have the answers to the questions. 1. What is the abi object inside the contract and what does it do? Is it the same as the one you get when you compile the ...
YulePale's user avatar
  • 1,843
20 votes

What is an ABI and why is it needed to interact with contracts?

think of "ABI" as an "API" at a low level. Think of it as the compiled version of an API (or as an API on the low level). As you know the contracts are stored as bytecodes in a binary format into ...
Badr Bellaj's user avatar
  • 18.8k
20 votes

web3.js import contract abi from .json file

I know the question is old, but I had some problems with this so I will share what helped me. To import the ABI from a JSON file, you can use the following code (assuming you already have your web3 ...
MAD's user avatar
  • 301
19 votes

How do you get a json file (ABI) from a known contract address?

Here is how you get the abi by using your local solc compiler: solc filename.sol --abi You also need the bin code to deploy the contract, which you can get as follows: solc filename.sol --bin If ...
sunwarr10r's user avatar
19 votes

How do you get a json file (ABI) from a known contract address?

If the contract is verified in Etherscan, the following script fetches the ABI and saves it to a JSON file. Use it like $ python fetch_abi.py <contract address> -o <target JSON file> ...
osolmaz's user avatar
  • 409
19 votes
Accepted

Deploying contract with constructor arguments via Geth RPC

It is quite complicated to get this correct, but here's some information on how to work it out. I'm using a simple contract as an example: pragma solidity ^0.4.2; contract Test { uint256 public ...
BokkyPooBah's user avatar
  • 40.3k
18 votes
Accepted

Pass a function as a parameter in Solidity

Functions (aka Methods) are specified by the ABI, and have a Method ID, which is the first 4 bytes of the sha3 (Keccak-256) of the method's signature. Here's an example of invoking someFunction on ...
eth's user avatar
  • 85.7k
18 votes

How get Constructor Arguments ABI-encoded?

You can use simple online tool to get abi-encoded constructor parameters https://abi.hashex.org. Just paste in abi and enter parameter values. Abi-encoded parameters would be automatically calculated. ...
Gleb Zykov's user avatar
18 votes

What is calldata?

calldata is where data from external calls to functions is stored. Functions can be called internally, e.g. from within the contract, or externally. When a function's visibility is external, only ...
schemar's user avatar
  • 331
17 votes
Accepted

Do I need a compiled contract just to get the ABI definition?

Seems like the contract address should be enough. You're right, it would be better if the ABI could be obtained by just looking at the contract. So why do contract writers need to also provide the ...
eth's user avatar
  • 85.7k
17 votes
Accepted

How do I get the implementation contract address from the proxy contract address?

Most proxy contracts typically have a public variable defined as a: address public implementation; Which defines the address of the implementation contract. You could then call it as a view function ...
Patrick Collins's user avatar
16 votes
Accepted

Convert contract arguments from JSON to ABI-encoded format

The page "Verify Contract" ask for "Constructor Arguments ABI-encoded". In your case the constructor has no parameters, so you can leave such field empty. In the general case when your constrctor ...
Ismael's user avatar
  • 30.6k
16 votes

etherjs equivalent of abi.encodeWithSignature

This is how it is done as of ethers.js v5: let ABI = [signature]; let iface = new ethers.utils.Interface(ABI); iface.encodeFunctionData(functionName, [param1, param2, ...]); Note that signature needs ...
Ahmed Ihsan Tawfeeq's user avatar
16 votes
Accepted

What is a function signature and function selector in solidity (and EVM languages)?

Function Signature A function signature is a combination of the function's name and the types of parameters it takes, combined together as a string with no spaces. For example, let's say you have a ...
Patrick Collins's user avatar
15 votes

Do I need a compiled contract just to get the ABI definition?

You don't need the source code, just the ABI. The ABI is produced when the code is compiled, but can be, and usually is, distributed separately. The ABI is essentially just a list of the function ...
Tjaden Hess's user avatar
  • 37.1k
15 votes
Accepted

How to get the contract ABI in new Remix IDE?

I cannot find the contract details to get the json interface anymore. If you select the compile tab, there you will find a button called details. When the details is clicked, a pop-up window will ...
Achala Dissanayake's user avatar
15 votes
Accepted

Passing Struct as an argument in call

By using abi.encodeWithSignature, your struct successfully to the low-level call. The code below is modified based on what you provided. pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; ...
QYuQianchen's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible