Skip to main content
181 votes
Accepted

When should I use calldata and when should I use memory?

memory and calldata (as well as storage) are keywords that define the data area where a variable is stored. To answer your question directly, memory should be used when declaring variables (both ...
Shane Fontaine's user avatar
45 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
  • 86.3k
32 votes

What is msg.data?

I had to dig a little deeper into the contents of msg.data for this feature. I thought it would be worth noting that variable length parameters like arrays, bytes and strings produce a more complex ...
aflesher's user avatar
  • 421
28 votes

calldata keyword as parameter in solidity v0.5.0 function?

As per the Solidity version 0.5.0 breaking changes here : Explicit data location for all variables of struct, array or mapping types is now mandatory. This is also applied to function parameters and ...
Aniket's user avatar
  • 3,545
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,588
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
19 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
  • 341
14 votes

When should I use calldata and when should I use memory?

memory variables are allocated by the callee and their value can be modified inside the function (they're mutable). You can declare a variable inside a function memory located as well as it's ...
R01010010's user avatar
  • 281
12 votes

Is sending some datas in the data field safe?

Generally, no! It can be dangerous. If you are asked to send such a transaction, you should understand what is the source code of the address you are sending to, and what function you might be ...
eth's user avatar
  • 86.3k
10 votes

What is msg.data?

Yes, in web3.eth.sendTransaction({from: ..., to: addressOfE, data: something});, then in contract E, msg.data will be the something. However, most of the time a contract handles msg.data indirectly ...
eth's user avatar
  • 86.3k
10 votes

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

In case you want to use a simple online tool to encode parameters you could use https://abi.hashex.org You insert the abi code to automatically parse parameters types or just enter them manually. In ...
Dmitry Mishunin's user avatar
9 votes

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

I was having a terribly hard time understanding the why part of this question myself, so I'd like to add one thing thanks to this excellent answer: "How these bytes are interpreted into structured ...
user1234's user avatar
  • 329
9 votes
Accepted

What is a function selector?

A function selector allows you to perform dynamic invocation of a function, based on the name of the function and the type of each one of the input arguments. For example, suppose you have: contract ...
goodvibration's user avatar
8 votes

Encoding/Decoding contract ABI data

In case you need an online tool to encode parameters to abi format you can use https://abi.hashex.org/. It has functionality to auto parse contract's abi to get function names and parameter types and ...
Gleb Zykov's user avatar
7 votes
Accepted

Remix IDE: What is the purpose of Calldata and Transact Tab

Ethereum transactions follow a certain low-level structure: from: address (signed by this) to: address value: uint (ether) data: message data bytes The first four bytes of data are a function ...
Rob Hitchens's user avatar
  • 55.5k
6 votes

How to decode input data from tx using python3?

If you know the contract ABI, call data could be decoded using pyethereum: from ethereum.abi import ( decode_abi, normalize_name as normalize_abi_method_name, method_id as ...
xuhcc's user avatar
  • 191
6 votes
Accepted

Decode Etherscan.io Contract Input Data

From Miguel Mota page, using Etherdelta ABI, and your transaction input I get { "name": "trade", "types": [ .. ], "inputs": [ "0", "16d8fceafcef3c0000", // <- amountGet "...
Ismael's user avatar
  • 30.4k
6 votes

What is calldata?

The Calldata is a read-only byte-addressable space where the data parameter of a transaction or call is held. Unlike the Stack, to use this data you have to specify an exact byte offset and number of ...
Yilmaz's user avatar
  • 1,715
6 votes
Accepted

can anyone help to explain calldataload

From the docs: calldata is a special data location that contains the function arguments, only available for external function call parameters. Every reference type, i.e. arrays and structs, has an ...
Shane Fontaine's user avatar
6 votes
Accepted

How to generate calldata for a function

You can execute the call the following way (members of addresses, abi.encode*, low-level calls): Example 1: Call using already calculated function signature (this answers your question) bytes memory ...
sea212's user avatar
  • 1,840
6 votes
Accepted

Understanding Dynamic Types in calldata

From Function Selector and Argument Encoding: All in all, a call to the function f with parameters a_1, ..., a_n is encoded as function_selector(f) enc((a_1, ..., a_n)) Therefore, the function ...
dwardu's user avatar
  • 1,418
5 votes
Accepted

Can msg.data be used as an identifier?

msg.data is usually ABI encoded information that indicates to the contract the function and parameters to invoke. Using standard tools, msg.data will be the same if the contract is called with the ...
eth's user avatar
  • 86.3k
5 votes

How to decode input data from tx using python3?

If you are using web3.py, you don't need an external module. You just need to initiate the Contract instance with its ABI. Then you run its decode_function_input method decoded_input = contract....
osolmaz's user avatar
  • 419
5 votes

Decoding contract output of web3 eth call

you can use web3 built-in functionality: web3.eth.abi.decodeParameters(typesArray, hexString); see link
fa1keh's user avatar
  • 51
5 votes

Contract call from a contract from a contract?

Yes, although obviously each contract has to execute the call itself. You can do this 1024 times until you reached the maximum depth. At that depth all new calls will fail. This even lead to ...
mafrasi2's user avatar
  • 948
5 votes
Accepted

How does a contract's constructor work and load input values?

In Solidity, arguments to the constructor are ABI encoded and appended to the compiled bytecode. The arguments are copied to the EVM memory using CODECOPY. In Etherscan, you can see that the last ...
eth's user avatar
  • 86.3k
5 votes
Accepted

Can calldata be used in every function visibility?

calldata can typically only be used with functions that have external visibility. However, Solidity will let you declare any function with calldata as long as you call it with calldata arguments. This ...
Ziyad Edher's user avatar
5 votes
Accepted

calldata ambiguity - likelihood of hash collision

This is actually something that can happen. The possibility of it happening randomly in the same contract is very low, which is 1/2^32. But if someone wants to make this attack happen she can easily ...
Allarious's user avatar
  • 358
4 votes

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

Just copy this json. This is contract ABI
Трипольский Пётр's user avatar
4 votes

What does "intrinsic gas too low" mean?

The keyword payable is needed on a function. See solidity docs: Payable for functions: Allows them to receive Ether together with a call. So, this doesn't work: function transfer(address _to, ...
Jim Sime's user avatar
  • 127

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