Questions tagged [function]
The function tag has no usage guidance.
119
questions
0
votes
1
answer
24
views
UniswapV2Router.sol addLiquidity() / UniswapV2Pair.sol mint() - Learning to read code
Can anyone explain to me what I fail to understand/misunderstand when reading the mint function of the UniswapV2Pair.sol contract after the addLiqudity function of the UniswapV2Router.sol initiates a ...
1
vote
2
answers
43
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 ...
0
votes
1
answer
29
views
i am compiling this lottery contract but the picWinner and getPlayers are not working
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0;
contract lottery{
address public manager;
address payable[] public players;
constructor(){
manager = msg.sender;
}
...
1
vote
1
answer
35
views
How to fix? warning (2018) function state mutability can be restricted to view
function withdraw() external onlyOwner {
if(block.timestamp < end || totalCollected < goal) {
revert CollectNotFinished();
}
}
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 ...
1
vote
1
answer
53
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 ...
4
votes
3
answers
287
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 ...
0
votes
1
answer
19
views
Unexpected overflow result from a function when inputting max uint256
I am looking at the following function tickUpper that is supposed to retrieve the 24 bits of a 256 bit number beginning at bit 208. It's cast to an int24 because it interfaces with uniswap ticks.
I ...
0
votes
1
answer
12
views
Why are these functions using %128?
I am looking at the following functions which (i) take a 7-bit number (up to 127) and add it to 256-bit number, starting 64 positions in from the right and (ii) read that 7-bit number given the 256-...
0
votes
0
answers
39
views
how to get a function's signature that have a structre as parametter
function createClone(
uint256 dbId,
launchpadLib.IDOInfo memory _idoInfo,
launchpadLib.IDOInfoTwo memory _IDOInfoTwo
) external{}
I have this funtion how can i make signature of this function with ...
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 &...
2
votes
2
answers
146
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 ...
2
votes
1
answer
74
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;
}
...
0
votes
1
answer
340
views
What is the correlation between "Hash" (Method ID) & "Name"
I was checking Etherscan and come across a deployed contract (Create contract), but the method id was 0x60a06040.
I then used https://openchain.xyz/signatures?query=0x60a06040 and found out that the ...
0
votes
1
answer
13
views
Do you have to explicitly state in the body of a function that it should return something?
I'm looking at the following function which is supposed to return (uint8 id, uint8 nextId). I see that in the body of the function, the return statement is within an "else" statement - see ...
0
votes
1
answer
38
views
Creating a local variable in an if statement?
I'm looking at a function that creates a local variable in an if statement. If someone called that function and the condition to the if statement was not triggered, that local variable wouldn't exist, ...
2
votes
1
answer
87
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 ...
0
votes
1
answer
20
views
Can you refer to a contract inside itself?
Sorry this is a very minor question but the following is part of a contract called LibOrders.sol. The function below calls LibOrders.cancelOrder....normally I think you would just put "...
1
vote
1
answer
67
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 ...
1
vote
1
answer
21
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 ...
1
vote
1
answer
59
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 ...
0
votes
1
answer
61
views
Revert inside a for loop
If there is a revert inside a for loop that is inside a function, and the revert is triggered, will the whole function revert?
2
votes
1
answer
43
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,...
1
vote
1
answer
32
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
) ...
0
votes
1
answer
952
views
How Can I Filter Ethereum Transactions by Method ID or Name, Similar to Etherscan's Advanced Filter Feature
I am working on a project where I need to retrieve all transactions associated with a specific method within a given block or set of blocks. As an example, Etherscan provides this functionality ...
1
vote
2
answers
174
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....
0
votes
1
answer
61
views
How can I modify this function to return my wallet address?
How do I modify this function to return my wallet address using uint160? I want to remove all the for-loop logic. I've created this contract and sent ETH to it, but I am having trouble getting the ETH ...
0
votes
1
answer
40
views
Function with both override and virtual keywords
What I understood from this is that if a function has virtual keyword, it can be overridden. And if a function has the keyword override means it is overriding another function. So, does the function ...
0
votes
1
answer
15
views
Hello. Is token mint allowed in this snippet? Or can it be mint again?
function mint(address user, uint256 value) external onlyOwner {
require(user == OWNER, "NOT_OWNER");
balances[user] = balances[user].add(value);
totalSupply = totalSupply.add(value);
...
0
votes
2
answers
271
views
Calling Aave Lending Pool V2 "Borrow" function returns "reverted with reason string 59"
My smart contract is trying to use stETH as collateral to borrow 250 WETH on the Aave Lending Pool V2, but the borrow function reverts with code 59:
BORROW_ALLOWANCE_NOT_ENOUGH = '59'; // User borrows ...
0
votes
1
answer
43
views
Call contract's function
I'm new in solidity and blockchain itself.
Typed myself contract for Voting in VSCode and tried to figure out how I can run code and research workflow and etc. During researching figured out that for ...
0
votes
1
answer
25
views
How to use another deployed smart contract functions?
What I want to do is deploy a smart contract with functions that other deployed smart contracts can call and get a response from.
How do I implement this? Is there any useful guides you guys know I ...
0
votes
1
answer
189
views
Chainlink Functions return an array or list of strings from Functions-request-source.js
Hope someone can help.
I am stuck trying to work out how best to extract the different string values from the returned bytes data.
Chainlink Function request source requires the return value to be a ...
0
votes
2
answers
59
views
How do you use `delete` on a function?
"If a function type variable is not initialised, calling it results in a failed assertion. The same happens if you call a function after using delete on it." is a quote from
the official ...
0
votes
0
answers
20
views
does empty function has security risks?
I have to implement the following interface in my contract
interface IMetadataRenderer {
function tokenURI(uint256) external view returns (string memory);
function contractURI() external view ...
0
votes
1
answer
28
views
ParserError in solidity
I wrote the following contract (for educational purposes):
// SPDX-License-Identifier: MIT
pragma solidity 0.8.8;
contract Coin{
holders[] public investors;
mapping(address=>...
1
vote
1
answer
92
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 ...
2
votes
1
answer
25
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 ...
8
votes
3
answers
310
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) ...
1
vote
1
answer
56
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 ...
1
vote
1
answer
74
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()?
0
votes
1
answer
99
views
Function isn't returning the uint256 value after initializing mapping
I'm facing a problem with the function return type in solidity. Here is my code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
contract Birth {
mapping(uint256 => bool) public ...
0
votes
1
answer
76
views
Modifier vs function call
What is more gas efficient and secure, using a modifier(for example only owner) or calling a function to verify state(calling a function that returns owner address and compares that to the address ...
0
votes
1
answer
200
views
Error When Passing Struct as Input to Function in Solidity
I'm trying to just call a function that has a struct argument...The thing is that Remix somehow doesn't recognize all the inputs from the struct in the function.
I tried making the image very ...
0
votes
1
answer
15
views
Function override error and abstract error after importing the contract
*this a contract for erc721:
contract erc721{
event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId);
event Approval(address indexed _owner,address indexed _approved, ...
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 ...
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 {
...
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 ...
1
vote
0
answers
40
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 ...
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 ...