Questions tagged [function-selector]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
74 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,039
2 votes
1 answer
155 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
3 votes
2 answers
588 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
76 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
5 votes
2 answers
788 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
64 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
158 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
10 votes
2 answers
5k 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
265 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
  • 675
2 votes
1 answer
110 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
189 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
158 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
0 votes
2 answers
1k 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
213 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
  • 715
3 votes
1 answer
387 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
  • 305
0 votes
2 answers
3k 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
  • 305
1 vote
1 answer
436 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
  • 245
0 votes
1 answer
5k 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
208 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
  • 305
2 votes
1 answer
1k 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
901 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
122 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
4 votes
2 answers
1k 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
803 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,335
0 votes
2 answers
383 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
745 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
608 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,173
30 votes
4 answers
32k 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,060