New answers tagged solidity-0.8.x
0
votes
Creating a local variable in an if statement?
Yes. It's like other languages it won't exist in out of the scope.
solc compiler give you Undeclared identifier error.
for example
if (everything) {
uint testVariable = 1;
}
require(testVariable == ...
1
vote
Accepted
Tick range of negative tick - Uniswap v3
In Solidity, you need to add a conditional statement to implement this correctly:
tickLower = tick / tickSpacing * tickSpacing;
if (tick < 0 && tick % tickSpacing != 0) tickLower -= ...
3
votes
Where in the code of this unstake function is ETH actually transferred?
The BridgeRouterFacet contract's unstakeETH() function:
function unstakeEth(address bridge, uint88 zethAmount)
external
nonReentrant
onlyValidBridge(bridge)
{
if (...
2
votes
Smart contract deployment pending forever
Your Go code calculates the gas price for the contract deployment transaction incorrectly — it sets it too low.
Your Go code seems okay (I think?) but maybe it fetched the gas price at the state (...
1
vote
Can you refer to a contract inside itself?
Yes, it is perfectly valid to call a function from the same contract using the full contract name and function name, i.e. LibOrders.cancelOrder(). This is often done to avoid name collisions, ...
0
votes
Can a function call itself?
This concept is called method overriding polymorphism in OOP programming, it is achieved by making more than one function with the same name but with different parameters.
It's used to change the ...
2
votes
Two people calling this function at exactly the same time
Even if two transactions are created at virtually the same exact time, there will be a definite order decided upon by the miner/validator of the block where the transactions took place.
This means ...
0
votes
Can a function call itself?
You can create a function that calls itself, the issue is ensuring that you don't get stuck in an endless loop that drains all your gas.
Take these contracts as an example:
Assume we will always pass ...
1
vote
Can you return something only some of the time with a function in solidity?
In Solidity, a function that returns a value doesn't need to do so explicitly.
For example take the following two functions:
function sometimes(uint x) public pure returns(uint y) {
if(x == 7) ...
1
vote
Revert inside a for loop
Yes, a revert within a loop inside a function triggers a full function revert due to its stack-based execution model, rolling back all changes made within the function.
1
vote
Performance and Gas Implications: uint vs int in Solidity Memory Variables
The main difference between uint and int is that uint only accepts positive values, while int accepts positive and negative values. They both store a 256-bit size value and as such, have the same ...
0
votes
Smart contract always returns the same hash even when provided with different input
The function isn't a view function. When you execute it it should return the transaction hash.
function randomHash(uint256 externalRandom) public {
bytes32 _swapID = keccak256(abi.encodePacked(msg....
1
vote
Accepted
Is it possible to define interface getters for arrays of structs?
Yes, it is possible to define a getter in an interface for an array of structs. Below is a complete example illustrating this.
Interface Definition
Firstly, you can define the interface with the ...
0
votes
Accepted
Calling performUpkeep(zeroBytes) results in 'function returned an unexpected amount of data'
Update: I was not able to fix my issue with ethers@v6.
I found out that my subscription simply wasn't created.
For some reason I'm unable to successfully create a subscription using this piece of code:...
Top 50 recent answers are included
Related Tags
solidity-0.8.x × 334solidity × 209
remix × 73
contract-development × 28
hardhat × 19
web3js × 17
ethers.js × 14
go-ethereum × 12
arrays × 11
erc-721 × 11
math × 11
blockchain × 10
tokens × 10
erc-20 × 9
struct × 9
function × 9
code × 9
truffle × 8
contract-design × 8
ganache × 8
nft × 8
openzeppelin-contracts × 8
brownie × 8
evm × 7
uniswap × 7