Questions tagged [function-selector]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
5 views

What does an array of a struct look like inside a function signature?

Let's say I have a struct like this: struct MyType { address token; uint256 amount; } function hello(MyType[]) external { ... What would my function signature (and, therefore, function ...
Patrick Collins's user avatar
0 votes
1 answer
33 views

How to change the offset of calldata value?

Suppose I have a contract below: contract Hack { Switch private target; constructor(address _target) { target = Switch(_target); } function test() external pure returns (...
Shubham's user avatar
  • 25
1 vote
1 answer
26 views

Low-level function call to other contract is causing revert with correct function selector

I have 2 contracts, FloorInfo and Elevator. I want to call the goTo(uint) in the Elevator contract from the FloorInfo contract using a low-level call, this happens in the go() function inside the ...
nostonksafrica's user avatar
1 vote
0 answers
19 views

Why doesn't this solution for ethernaut work?

I am working on the ethernaut CTF level (code below)...I need to take over ownership of the instance (it's been deployed). I thought I could do it by sending a small amount of ETH to the instance ...
user127148's user avatar
1 vote
1 answer
865 views

How to call a contract function only using function hash in ethers.js?

I would like to call a contract function, but I do not have the contract's abi. Since none of the decoders can decode the function name, the only solution I see is calling the function using its hash. ...
Nal Luksic's user avatar
  • 1,137
3 votes
1 answer
338 views

How to calculate the 4byte selector using Cast?

I am using Foundry, and I need to calculate the 4-byte selector of a custom error. How can I do this with the cast CLI?
Paul Razvan Berg's user avatar
4 votes
2 answers
1k views

How to convert `bytes4` to `bytes memory` in Solidity?

bytes4 is a commonly needed data type in Solidity, due to its use in msg.sig and, more broadly speaking, in function selectors (e.g. Contract.func.selector). How can one convert bytes4 to bytes memory?...
Paul Razvan Berg's user avatar
0 votes
1 answer
105 views

Cannot get selector of inherited functions

contract A { uint256 x; function myFunc(uint256 _x) public { x = _x; } } contract B is A { function myFunc1(uint256 _x) public { x = _x; } } contract Test { ...
Daniel Gretzke's user avatar
6 votes
2 answers
1k views

What is a function's function signature if it uses a custom type? (Stuct, enum, etc)

I have the following Enum that is an input to a function enum Cat { Tabby, Rascal, Cool } function hiMom(Cat myCat) public { What is the function signature of hiMom(Cat)?
Patrick Collins's user avatar
0 votes
0 answers
10 views

I initiated a swap on blockchain, but intead of going to receive adress it created a contract without abi or functions in it [duplicate]

I initiated a swap on bsc blockchain, but instead of funds going to receive adress it created a contract without abi or functions in it. Is it possible to receive the funds back? I own the created ...
Jeepeedk's user avatar
2 votes
1 answer
141 views

Any way to call contract function without showing in transactions on ethscan/bscscan?

I'm trying to figure out how a particular smart contract (or set of contracts) is operating. It seems to be executing a function but the function call never shows up as a transaction on bscscan (yes ...
Marc's user avatar
  • 257
1 vote
2 answers
267 views

Can you explain why do we have to access bytes variable "functionCallData" four times in order to get selector?

Why would we get function selector like this and why do we use that bytes variable functionCallData do many times? Thanks in advance! function getSelectorTwo() public view returns (bytes4 selector) { ...
Ethguy's user avatar
  • 33
11 votes
2 answers
8k views

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

I've heard the term "function signature" as well as "function selector", what are they? What are they for?
Patrick Collins's user avatar
0 votes
0 answers
390 views

Get functions selectors of contract

Is it possible to get all the function selectors from a contract using only Solidity and/or assembly? Thanks!
dNyrM's user avatar
  • 936
2 votes
1 answer
145 views

External Function as Function argument

I am trying to figure out how the calldata looks, when I pass a function as a function argument. For example, function foo(function(uint) external callback) external {} I assume it is the methodId of ...
Nikoliale's user avatar
0 votes
1 answer
247 views

Match a solidity function selector with a dynamic array to a vyper function selector

I have a solidity function selector: bytes4 selector = bytes4(keccak256(bytes("rawFulfillRandomWords(uint256,uint256[])"))); (The selector here is 0x1fe543e3) And in this function selector, ...
Patrick Collins's user avatar
1 vote
2 answers
201 views

Cannot get correct MethodID from a function

I am trying to derive the MethodID from the function, based on this post. However, when I look at this transaction on Etherscan, I cannot see how swapExactTokensForETHSupportingFeeOnTransferTokens(...
gioro's user avatar
  • 15
1 vote
2 answers
2k views

Fastest way to find the function in a contract from it's selector?

Let's say I have a function selector: 0xa9059cbb And I have a contract as such: // SPDX-License-Identifier: MIT pragma solidity ^0.8.7; contract CallAnything { function balanceOf(address ...
Patrick Collins's user avatar
0 votes
3 answers
266 views

Method with struct not presented over Etherscan

In my smart contract I have some methods that get a struct as an input: contract MyContract { MyStruct { uint[] arr; address[] addresses; } function myFunction(MyStruct[] structs) ...
forhas's user avatar
  • 785
3 votes
1 answer
461 views

Get interfaceId from interface in ethers js or hardhat

Solidity has this wonderful way to quickly get the interface id from an interface. Suppose I have the interface interface undernose { function overmouth() external; } then solidity (at least in ...
Marlo's user avatar
  • 329
1 vote
2 answers
4k views

How do I decode call data in solidity?

I have data in memory that is used for a function call, so I guess that makes it call data rather than a calldata (data location). This call data, say bytes memory data, consists of a selector and the ...
Marlo's user avatar
  • 329
1 vote
1 answer
600 views

generate function name yielding a specific function selector

Suppose I have a function with arguments (address _to, uint256 number) The function selector is found using let signature = "name(address,uint256)"; let selector = Keccack256(signature) ; I ...
qubitz's user avatar
  • 287
0 votes
1 answer
7k views

How to call certain solidity function based on python function parameter

I was wonder if it's possible to call a smart contract function based on a parameter sent to my function caller. From some research I did, i was able to find a function called getattr(). I was ...
Jungle Nuts's user avatar
2 votes
0 answers
255 views

Is there a way to call a function via a selector from within a contract?

In the case of calling a function with signature foo(uint256) from contract A, I could use this construction in solidity: address(A).call(abi.encodeWithSignature("foo(uint256)", 100)); // or ...
Marlo's user avatar
  • 329
2 votes
1 answer
2k views

Can you call internal functions of a smart contract using the function selector?

I have the following contract: // SPDX-License-Identifier: MIT pragma solidity ^0.8.9; contract Selectors { bool public called; function callOtherFunc() public { bytes4 func = ...
Patrick Collins's user avatar
0 votes
0 answers
1k views

Constructing hex data payload for contract interaction

I am trying to construct the data payload as described here and quoted below for interacting with a contract: https://github.com/ethereumbook/ethereumbook/blob/develop/06transactions.asciidoc#...
kayatela's user avatar
  • 101
4 votes
0 answers
134 views

Why EIP-165 consider 0xffffffff value to be invalid id?

EIP-165 aims to provide a way for a contract to communicate whether it has implemented a certain interface or not. The standard defines the interface identifier as the XOR of all function selectors in ...
Ilya Loskutov's user avatar
5 votes
2 answers
2k views

How to load the first 4 bytes from a bytes calldata var?

It is common for calldata to be encoded as bytes calldata when developing contracts in Solidity. I need to extract the function selector from such a bytes var. What's the best way to load the first 4 ...
Paul Razvan Berg's user avatar
1 vote
0 answers
859 views

Function selector computed differently for libraries?

As documented in various places, the function selector is computed as the first four bytes of the keccak256 hash of the function header, which consists of the function name followed by the list of ...
gernot's user avatar
  • 155
7 votes
1 answer
7k views

explanation of appending .selector in solidity smart contracts

I'm trying to understand what .selector means when appended to logic wrapped up inside of functions definitions. I've tried to read the section in soliditydocs, but it doesn't seem to answer my ...
NowsyMe's user avatar
  • 1,365
0 votes
2 answers
393 views

What is the advantage of the function selector?

I can't understand the advantage of function selector. Following link What is a function selctor? uses function selector to invoke a function of another contract but it uses the statements: ...
zak100's user avatar
  • 1,406
14 votes
2 answers
10k views

What is a function selector?

I am reading an article, it says: To enable deployment on the Ethereum platform, the contract functions are compiled into EVM bytecode and a piece of code called function selector is added, ...
zak100's user avatar
  • 1,406
3 votes
1 answer
787 views

Function selector of function that takes enum as argument

If a function takes an enum as a parameter function foo(MyEnum arg1, uint256 arg2) public returns (bool); how do I properly compute the function selector for that function?
matthias_buehlmann's user avatar
4 votes
1 answer
678 views

Function selector for constructor & fallback function?

According to https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI, function selector is hashed from function name and list of its arguments put inside (). For example, with function deposit(...
user311703's user avatar
4 votes
4 answers
1k views

Should UIs handle 4Byte function selector collisions?

With 4 bytes collisions are possible. But they are not very likely. Currently in the 6,846 entries in the 4Byte.directory there are no collisions. Still they are possible. Now I wonder if UIs should ...
ligi's user avatar
  • 1,183
30 votes
4 answers
33k views

Calling function from deployed contract

I want to know how to instantiate an existing contract deployed on the blockchain using its address. e.g: contract A { function f1() {} } A is deployed on the blockchain, and in contract B I ...
Sig Touri's user avatar
  • 1,090