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 ...
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♦
- 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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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♦
- 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♦
- 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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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
"...
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 ...
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 ...
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 ...
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 ...
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♦
- 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....
5
votes
Decoding contract output of web3 eth call
you can use web3 built-in functionality:
web3.eth.abi.decodeParameters(typesArray, hexString);
see link
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 ...
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♦
- 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 ...
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 ...
4
votes
What is an ABI and why is it needed to interact with contracts?
Just copy this json. This is contract ABI
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, ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
calldata × 187solidity × 86
abi × 26
contract-invocation × 20
contract-development × 17
memory × 17
web3js × 16
evm × 16
transactions × 15
assembly × 11
delegatecall × 11
remix × 9
bytes × 9
data-types × 7
gas × 6
storage × 6
ethers.js × 6
raw-transaction × 6
addresses × 5
encoding × 5
callcode × 5
blockchain × 4
dapps × 4
arrays × 4
struct × 4