Skip to main content
Share Your Experience: Take the 2024 Developer Survey
179 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
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
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.9k
41 votes
Accepted

What is the ethereum transaction data structure?

An Ethereum transaction - as in, what you pass to sendRawTransaction() - consists of the following fields, in order and RLP-encoded (note that the field names are not part of the encoded data): nonce ...
jimkberry's user avatar
  • 1,316
31 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
  • 411
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,568
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
  • 85.9k
10 votes

Encoding/Decoding contract ABI data

If the question is about abi params, you can take a look at these two web3.js files: https://github.com/ChainSafe/web3.js/blob/0.20.7/test/coder.encodeParam.js https://github.com/ChainSafe/web3.js/...
debris's user avatar
  • 861
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

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
  • 85.9k
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
Accepted

with Web3.js, display sendTransaction data field from function call

Use getData. Example: // Get the call data, so you can call the contract through some other means var myCallData = myContractInstance.myMethod.getData(param1 [, param2, ...]); // myCallData = '...
eth's user avatar
  • 85.9k
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

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

To use eth_call, the tricky part is providing the data, which is ABI encoding the function you want to invoke and its arguments. It's essential to use canonical types, so double(int256) instead of ...
eth's user avatar
  • 85.9k
7 votes
Accepted

Private chain: Extracting the "data" from an account?

The data you're sending is part of the transaction, but it is not "added" to the account. There is storage associated with accounts (accessed via eth.getStorageAt(address,location)) but it will be ...
Tjaden Hess's user avatar
  • 37.1k
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.3k
6 votes
Accepted

Private chain: Maximum size of "data" field in an Ethereum transaction?

In genesis.json you can set the block gas limit and then see How can I stop the block gas limit on a private chain dropping to the public chain default? Does it mean that I can transfer any amount ...
eth's user avatar
  • 85.9k
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.5k
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,695
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

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
  • 85.9k
5 votes

How to read a data sent to my Smart Contract

Assume you have a solidity function inside your smart contract which accepts data in the form of e.g. an integer called xyz: function takeData(int xyz) Now in e.g. geth you can create an instance of ...
SCBuergel's user avatar
  • 8,774
5 votes

How can I send some message from contract to address

There is something specifically for this purpose, which is called Whisper In a nutshell whisper is a communication protocol for DApps to communicate each other. Example Usage var shh = web3.shh; ...
niksmac's user avatar
  • 9,673

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