119
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♦
- 78.7k
115
votes
Accepted
What is an ABI and why is it needed to interact with contracts?
ABI stands for application binary interface.
In general, an ABI is the interface between two program modules, one of which is often at the level of machine code. The interface is the de facto method ...
70
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 ...
38
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♦
- 78.7k
33
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♦
- 78.7k
31
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 ...
25
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 ...
24
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 ...
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)
);
21
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 ...
21
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♦
- 78.7k
20
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 ...
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 ...
19
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 ...
17
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♦
- 78.7k
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♦
- 78.7k
17
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 ...
16
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 ...
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 ...
16
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.
...
16
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)
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 ...
15
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>
...
15
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 ...
14
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 ...
14
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 ...
13
votes
What is the best way to get the JSON ABI after deploying a contract with Truffle to Ganache or Kovan?
when you run
$ truffle compile
truffle creates and saves a json file per contract in /yourProjectPath/build/contracts. In this json file you'll find the abi, the bytecode, the topics (if you have ...
12
votes
Accepted
How is an ABI stored in bytecode?
It's the job of the compiler to produce the correct EVM bytecode so that as you say the MethodID "piece of data will end up jumping to the appropriate address for that function in the bytecode of ...
eth♦
- 78.7k
12
votes
Accepted
Where to find contract ABI in new version of online remix solidity compiler?
Here are instructions to find contract ABI using online remix solidity compiler.
In the "Compile" tab, click on the "Details" button.
On the modal, go down to the "Interface" section. Click the copy ...
12
votes
What is a good alternative to `ContractTranslator.encode_abi`
With Brownie
Brownie allows you to generate calldata using the ContractTx.encode_input method:
>>> token
<Token Contract object '0x79447c97b6543F6eFBC91613C655977806CB18b0'>
>>&...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
abi × 421solidity × 154
web3js × 76
contract-development × 52
contract-invocation × 35
etherscan × 33
contract-deployment × 26
bytecode × 26
go-ethereum × 25
encoding × 22
calldata × 21
transactions × 20
decoding × 18
javascript × 17
web3.py × 17
remix × 15
evm × 14
truffle × 13
ethers.js × 13
contract-design × 12
tokens × 12
json-rpc × 12
solc × 12
python × 11
verify × 11