Skip to main content

Questions tagged [function]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
36 votes
1 answer
26k views

What does the keyword `super` in Solidity do?

I came across the super keyword in Solidity in the context of overriding functions. What does it do?
SCBuergel's user avatar
  • 8,774
8 votes
3 answers
294 views

The redundant `_from` parameter in the `transferFrom` function of an ERC721

The Non-Fungible Token Standard (described in EIP-721) specifies, among other things, the signature of the transferFrom() function: function transferFrom(address _from, address _to, uint256 _tokenId) ...
Iaroslav's user avatar
  • 365
4 votes
3 answers
206 views

Calling private functions using Yul ( Solidity )

I'm currently learning Yul in Solidity and experimenting with the call() function to call other functions in inline assembly. I've noticed that as soon as a function is set to private, I receive a ...
Pintus20's user avatar
4 votes
1 answer
35 views

Is it possible to use interface functions as types?

I would like to use a function defined in an interface as a function type, like this: pragma solidity >=0.8.17; interface Foo { function myFunction() external; } contract Contract { ...
Paul Razvan Berg's user avatar
2 votes
2 answers
133 views

What is an Internal function type variable?

I was going through solidity documentation and found this paragraph inside "Function Types" section https://docs.soliditylang.org/en/v0.8.21/types.html#user-defined-value-types A function of ...
ImBatman's user avatar
2 votes
2 answers
681 views

modifier vs function which method is more efficient in terms of gas?

contract test { address public _onwer; error NotOwner(); modifier OnlyOwner1() { if(msg.sender != _onwer) { revert NotOwner(); } _; } function OnlyOwner2() ...
imelon2's user avatar
  • 570
2 votes
1 answer
83 views

Where in the code of this unstake function is ETH actually transferred?

I am looking at this repo, which is contracts for a decentralized pegged asset issuance system backed by liquid staking tokens like rETH. Specifically, I have a question about the functions unstake in ...
auditor_chick's user avatar
2 votes
1 answer
65 views

Possible way to hack Solidity into executing a function directly from a struct as a method? (v0.8.20)

pragma solidity 0.8.20; contract SolidityLimitTest { mapping (address => Hack) private Hackable; struct Hack { uint amount; function(uint) returns (uint) ten_x; } ...
Ashraile's user avatar
  • 125
2 votes
1 answer
40 views

Invoking a function with different amount of input than the function takes

function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } function sub( uint256 a, uint256 b,...
Harsh Dhankhar's user avatar
2 votes
1 answer
23 views

SOLIDITY NOOB QUESTION. Is it necessary to specify that a function is a view function if it's obviously a view function?

For example: function contains(address _key) public view returns (bool) { return map[_key] != 0; } I don't know how this could be manipulated to change the state of anything, so to me it ...
Paul DeLucia's user avatar
2 votes
1 answer
3k views

Can solidity function have optional parameter?

buyCoffee function has only 2 parameters. But if I call buyCoffee function with tip parameter in the test script, it does work. I tried to find some references in the ethers.js document but I couldn't....
Shift_that's user avatar
2 votes
1 answer
48 views

DAO like functionality on Gnosis?

I am a Gnosis newbie. Want to set up a safe for an investor group. It seems like the safe has awesome functionality for that. As the group potentially expands beyond my small circle, may offer ...
Daniel Faber's user avatar
2 votes
1 answer
201 views

Random function

Is this function safe? I want to generate a random number without any external input. abstract contract F { //current block time when the contract was created uint256 private currentTime=block....
Vlad Cristian Stanica's user avatar
2 votes
2 answers
159 views

expected { but found constant

My code is: function equity_in_Hadcoins(address investor) external constant returns (uint) { return equity_Hadcoins[investor]; } // getting the equity in USD of an investor function equity_in_usd(...
Danny's user avatar
  • 21
2 votes
1 answer
44 views

Is there an EVM compiler that supports coroutines? (e.g. generator functions)

With coroutine I mean a subroutine that can be paused and resumed from another subroutine; preserving its internal state across pauses and resumes. For example, a feature similar to: Javascript's ...
Jesbus's user avatar
  • 10.5k
1 vote
2 answers
228 views

Why and when to user require(bool) on functions

I want to understand when (and why) it's necessary to use this statement : require(sent, "failed to send ether") i could just do somethink like this instead:
Arthur Breguez's user avatar
1 vote
1 answer
291 views

If not in the EVM, where do internal functions execute?

The Ethereum documentation says that internal functions are not executed in the EVM, while external ones are: If not in the EVM, where are internal functions executed? Does this simply mean that ...
RSW's user avatar
  • 139
1 vote
1 answer
63 views

Two people calling this function at exactly the same time

I was looking at Rocket Pool's docs on interacting with other contracts and they included a simple example function that another protocol could use to accept deposits of ETH, forward it to RP, and get ...
auditor_chick's user avatar
1 vote
1 answer
113 views

Does it make any sense to specify reference type function input parameters as calldata if the given function is only called contract to contract?

As far as I am aware contract to contract calls store input arguments in memory. Or put more precisely they store them in memory and they can be accessed with CALLDATALOAD within the the new call ...
FreddyC's user avatar
  • 311
1 vote
2 answers
295 views

Where are Function stored in EVM?

I know that global variables are stored in slots of storage layout. But where are the functions stored? I would like to know technically why.
imelon2's user avatar
  • 570
1 vote
2 answers
359 views

Can I import specific functions from other contracts and not the whole contract?

I am importing Access.sol by OpenZeppelin ("@openzeppelin/contracts/access/AccessControl.sol") in a contract. The main functions I am concerned with are setupRole(),hasRole() and grantRole()....
brownWellick's user avatar
1 vote
1 answer
200 views

Private variables with public view functions

In the Openzeppelin ERC721.sol contract, there are private variables introduced: // Token name string private _name; // Token symbol string private _symbol; These variables are then assigned a ...
David's user avatar
  • 153
1 vote
1 answer
216 views

Solidity: Restrict access to functions

Today I found a contract on etherscan providing a restriction on one of the two existing "withdraw" methods and I asked myself: If you would call this function withdraw() as not the owner, ...
Robert Bahn's user avatar
1 vote
2 answers
40 views

How concurrency works on Ethereum?

If 2 persons call the function deposit in my smart contract at the same time, sending 100 USDC each, and in my deposit function I use balanceOf(address(this)) to check the balance of my contract in ...
Ryan Holanda's user avatar
1 vote
1 answer
20 views

Can you return something only some of the time with a function in solidity?

I am looking at a function that says it returns two uints, but the return statement is inside an else statement, so obviously there are conditions under which nothing would be returned. Can you have ...
auditor_chick's user avatar
1 vote
1 answer
31 views

When calling a custom function on an ERC721 it keeps reverting when called from the frontEnd but works if called from remix

I am having an issue calling a function on one of my contracts. I have an ERC721 contract that has a function getTokenUnlockableContent. function getTokenUnlockableContent( uint256 tokenId ) ...
Tebbo's user avatar
  • 11
1 vote
2 answers
148 views

how does swapExactTokensForETHSupportingFeeOnTransferTokens work and its inputs

I tried many things on inputs but unfortunately I am just receving a gas error (the one that says would likely fail if continued) How does the function input works exactly? uniswapV2Router....
Lupus7's user avatar
  • 11
1 vote
1 answer
52 views

Is there a decentralized version of Cloudflare Workers?

Is there a decentralized version of Cloudflare Workers or some comparable service like AWS Lambda functions or GCP Cloud Functions? I would love a blockchain based, or just a decentralized version of ...
ChristianOConnor's user avatar
1 vote
1 answer
87 views

Getting two different booleans calling a function 2 times in a row

I tried to create a function which could return me 2 different booleans after I call it two times in a row. I tried my best to use different random methods like storing block.timestamp in an uint, or ...
Vagner's user avatar
  • 21
1 vote
1 answer
24 views

What are the advantages/disatvantages to specify a struct param in a function as calldata vs. memory?

If I am not modifying the input parameter in the function body are there any reasons a reference type parameter should be labeled as stored in memory? More generally what are the reasons to go for ...
FreddyC's user avatar
  • 311
1 vote
1 answer
211 views

If the smart contract does not include the withdrawal function, will that ether be stored in the smart contract for life?

I am making a function to send ether to a smart contract and send the ether in the smart contract to another person. If the smart contract does not include the ability to send ether to other people, ...
imelon2's user avatar
  • 570
1 vote
1 answer
277 views

Function cannot be declared as view because this expression (potentially) modifies the state

Compiling the contract returns this error. TypeError: Function cannot be declared as view because this expression (potentially) modifies the state. --> contracts/certification/token/...
Sky's user avatar
  • 2,332
1 vote
1 answer
30 views

Different number of parameters between client and contract functions

From this repository: https://github.com/dabit3/polygon-ethereum-nextjs-marketplace Look at createToken function inside the JavaScript file (pages/create-nft.js): let listingPrice = await contract....
NineCattoRules's user avatar
1 vote
1 answer
81 views

Solhint: Why should I avoid multiple calls of "send" in a single transaction?

function withdrawAll() public payable onlyOwner { uint256 _each = address(this).balance / 4; require(payable(t1).send(_each), "Account is being paid out"); require(payable(t2)....
Gray Blanchard's user avatar
1 vote
1 answer
2k views

Why can't I access the Uniswap v3 Factory .getPool() function?

As a personal exercise, I am trying to convert the following Uniswap v2 project to Uniswap v3: Uniswap token price monitoring (this is not swapping), i.e. ETH/DAI https://www.youtube.com/watch?v=...
ElHaix's user avatar
  • 187
1 vote
0 answers
11 views

Tracking total sold not total supply?

I am setting up a pre sale contract, it enables users to purchase the tokens via a prelaunch which they are distributed from the owners (our contract owners) wallet when a user buys them. How are ...
Jim Mike's user avatar
1 vote
1 answer
51 views

generate url in smart contract, based on block.chainid and address(this)

For the past few days I have been looking into creating a simple function to generate a url based on block.chainid (uint256) and address(this). The idea is as follows: function url() public view ...
Cloudronaut's user avatar
1 vote
0 answers
15 views

Attack vector in direct transfer function in EC721

How the attack vector would look like in case of direct transfer function in EC721 standard. It is described in the comment A marketplace is transferring an NFT from Bob to Mary (among many other &...
ramiz_karaeski's user avatar
1 vote
1 answer
49 views

How can I execute a call from a contract using another contract?

I own a contract (contract A), which in turn, when deployed, created a secondary contract (Contract B). I have funds trapped in contract B, contract B, has a function that allows its owner to withdraw ...
Leandro Loures's user avatar
1 vote
1 answer
84 views

How I do I calculate the price of a Token as the amount of the token bought increases

Let say I created a Min price = 0.00056 ether for 150 coins which is the Min amount and the Max price = 0.1 for 20,000 coins which is the Max amount. What will be the price of the coin when I buy 1000 ...
jacobs david's user avatar
1 vote
1 answer
62 views

What is Solidity's equivalent of raw_call()?

I'm wondering, does Solidity also have a raw_call() function like Vyper which sends a byte[] array (payload) as calldata to a specific address? If so, what is that function? Is it also raw_call()?
MuellerSachs's user avatar
1 vote
1 answer
22 views

Declaration error: undeclared identifier error in remix while using exiting Owner contract's function getOwner. Kindly help in solving

function withdraw() external isOwner() { address payable owner = address(uint160(getOwner()));//**this is the line I get err owner.transfer(address(this).balance); } owner contract: function ...
Baby's user avatar
  • 29
1 vote
0 answers
39 views

How to identify where coin/token value is changed

I'd like to build an algorithm that analyzes value creation, transfer and destruction on a blockchain (such as new ETH minted, ETH gas burned, ERC-20 tokens transferred, etc.). Assuming I have a ...
Michael C's user avatar
1 vote
0 answers
30 views

Using interfaces as function parameters in solidity

Is it recommended to use contract interfaces as function parameters in solidity against using address. like... function doSomething (IERC20 token) external { ... } rather than function doSomething (...
Michael Amadi's user avatar
1 vote
0 answers
108 views

Solidity function generic data type parameters

I have two structs: Struct A; and Struct B; I've two arrays: A[] a; and B[] b; And a function: getIndex() // ^^^*Generic: based on struct type passed* function getIndex(A/B memory [] ...
blest's user avatar
  • 111
1 vote
0 answers
336 views

Ethereum contract "checksum" and contract simulating

I was looking at different contract simulators and I was wondering how are they made. I can see that they determine all of the functions that a given contract have, eg: --------------------------------...
Kacper's user avatar
  • 53
1 vote
0 answers
102 views

Pure function that reads from storage, compiler bug?

I just came across this while testing around with the Diamond Storage pattern. Here is a 'pure' function that reads from storage. This had me wondering, is there actually any difference between pure ...
phaze's user avatar
  • 1,615
1 vote
1 answer
33 views

What does {...} as a part of a function call mean?

In the function swapExactETHForTokens of Uniswap is called like this: uniswap.swapExactETHForTokens{value: msg.value}( amountOut, path, msg.sender, ...
Markus736's user avatar
1 vote
0 answers
58 views

What the this keyword means?

im doing the ethernaut course. what does this mean ? I know what for exemple address(this)means, it s the address of the smart contract but like what does it means when the this is alone like this?
disqid's user avatar
  • 13
1 vote
0 answers
197 views

Best practice for calling function from another contract

I'm a bit of a beginner so I'm sorry if I misphrase anything, but I haven't been able to find a definitive answer on this yet. I'm going through some tutorials which list out a few ways to call ...
flbzer's user avatar
  • 113