Questions tagged [solidity]
Solidity is a contract-oriented, high-level language whose syntax is similar to that of JavaScript and it is designed for writing smart contracts in Ethereum to run on the EVM. Solidity is statically typed, supports inheritance, libraries and complex user-defined types among other features.
17,654
questions
1
vote
1
answer
95
views
Why does Metamsk display the sign data as unicode question marks and other various characters when signing a message with Viem?
I'm trying to sign a message in Viem and recover the signer in Solidity, it works as expected, however, the Metamask pop-up window displays the data to be signed incorrectly.
Here is my Viem ts code:
...
1
vote
1
answer
199
views
How can I create a message hash in Solidity that matches Viem?
I'm creating a message hash with Viem in typescript and in Solidity, however, I can't seem to get the hash in Solidity to match the one created with Viem.
My viem code:
const hashedMessage = ...
0
votes
1
answer
42
views
Solidity Smart Contract Behaving Weird on Goerli Testnet
I have a vite-project in typescript that I want to have eth deposit and withdrawal capability.
I'm new to the crypto space and trying to implement a simple wallet contract using Truffle on the ETH ...
0
votes
0
answers
17
views
How do you calculate percentage change for token supply?? Is there a need for scaling factor?
Is this how you calculate percentage change of new token price? I am not using any oracle.
// START_REBASING_SHARE_PRICE is 1e30.
uint256 percentChange = (sharesAfter * ...
1
vote
0
answers
19
views
Error when calling a function inside contract
I have a simple contract for getting a greeting and changing the greeting message.
I am getting this error when calling the getGreeting function.
error: Error: call revert exception (method="...
0
votes
1
answer
56
views
Transaction failed-CALL_EXCEPTION
I deployed smart contract to testnet and i got error can someone help me debug this
Code:
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@...
0
votes
1
answer
65
views
Smart contract error Error: transaction failed
I deployed smart contract to testnet and i got error can someone help me debug this
Code
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@...
1
vote
1
answer
30
views
How to create a smart contract for game entry?
I am fairly new to smart contracts, and my team currently creating a game to collect entry fees of 0.01 ETH. Initially was going to let people transfer 0.01 ETH to our main wallet address, and have a ...
1
vote
0
answers
14
views
How can I call a function from another contract with it's reference | TypeError: contract.functionName is not a function
I've two smart contracts in my hardhat environment, really small. They are given below:
contract Parent {
Child[] public domainRegistries;
function createChild() public returns (Child) {
...
0
votes
1
answer
87
views
Code validation
Hi i want to deploy my first smart contract to the Eth mainnet and this require a lot of money and i am very scared can someone want to help me and validate this code for any errors becouse i cant run ...
0
votes
0
answers
25
views
The receiving account ether's does not increase whilst the sender ether's decrease
I got that function that sends contributions to the smart contract as i thought
everything works perfectly when the sender uses it to send contributions
his account balance decreases and that line is ...
0
votes
1
answer
61
views
Unique Reports - Chainlink OCR2Base.sol
I was checking the OCR2Base.sol file in the CCIP repo and was wondering what the i_uniqueReports variable stands for. Especially, why would it change the transmit() function such that the expected ...
1
vote
1
answer
81
views
abi.encode an already encoded parameter
I want to use an already abi-encoded parameter and encode it again with another value. Encoding works, but I cannot figure out the decoding. I technically could decode it and encode it again with that ...
0
votes
0
answers
11
views
Solidity design pattern drawbacks
I was ask by a friend to give feedback on his solidity project. I came over a general design pattern issue, which is not good from an object oriented point of view. I try to outline the projects ...
0
votes
1
answer
21
views
What could go wrong with saving data on mapping for the sake of UI use?
I have a Token contract and I want to record the token price once per day.
So I was thinking that to cut the trouble of going trough creating a server to save the data or using a service API I would ...
0
votes
1
answer
25
views
getting error Transaction has been reverted by the EVM
I am using ai to write solidity contract and below is the contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
// Import the A2AToken contract from the A2A Token file
import "./...
0
votes
0
answers
18
views
Purposely failing Low-Level Call
Does this code below have a vulnerability?
burnAddress.call.value(msg.value)("");
//update state
burn Address is a trusted contract, which ...
0
votes
0
answers
11
views
Problems with Gas Consumption When Deploying a Smart Contract with a Function for Uniswap Liquidity
I am encountering an issue when deploying my smart contract on the network. The contract deploys successfully without the inclusion of a function that handles a 2% liquidity tax, which is supposed to ...
1
vote
0
answers
35
views
Calculate price of 1 UNI-V2-LP tokens
Calculating the price of 1 token can be done by
1 token in wei = _reserve0 / _reserve1
But how would I calculate the price of 1 UNI-V2-LP token?
Naively - I think that it's 50/50 tokens/weth, so if we ...
0
votes
0
answers
7
views
reentrancy vulnerability Replication Failure
Vulnerability replication fails, returns false when calling Amoney.withdraw via the Battack contract, and fails to trigger the fallback function.help!
//victim contract
// SPDX-License-Identifier: MIT
...
0
votes
0
answers
24
views
UniswapV2 swapExactTokensForTokens Question
I have question does UniswapV2 swapExactTokensForTokens function charge fees ? And if yes does expected amount input should be like this Expected price after fee subtraction?
1
vote
2
answers
51
views
Prices on Dexes
Hi I have code that fetches price from uniswap v2
ratio0ToPrice = (amount0In, amount1Out) => {
if (Number(amount1Out) === 0) {
return "Infinity";
}
return 1 / (Number(amount0In)...
4
votes
3
answers
139
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
0
answers
13
views
How to perform Swap (via uniswap) only when requirement is true?
I am currently in the process of writing a contract for a token on the Ethereum blockchain. However, I have encountered a problem. I am trying to link a swap function for uniswap to a condition (that ...
0
votes
0
answers
14
views
How to build Timelock Dao with Access Control?
import {TimelockController} from "@openzeppelin/contracts/governance/TimelockController.sol";
contract DaoTimelockController is TimelockController {
constructor(
address _core,
...
0
votes
0
answers
5
views
I am creating a hierarchy RBAC, should you use _grantRole or _setRoleAdmin first?
Was wondering if you should _grantRole first or _setRoleAdmin first based on OZ AccessControl
_grantRole(CoreRoles.GOVERNOR, msg.sender);
// Initial roles setup: direct hierarchy, ...
0
votes
0
answers
22
views
Error: cannot estimate gas; transaction may fail or may require manual gas limit. I cannot see which gas limit it refers
I am trying to deploy a SimpleStorage solidity contract using javascript on WSL studio and Ganache.
The terminal talks about gas fees though neither my solidity code nor my javascript code talks about ...
0
votes
0
answers
13
views
How to set COUNTING_MODE for openzeppelin?
My question is there anything wrong with my function?
function COUNTING_MODE()
public
pure
virtual
override
returns (string memory)
{
return &...
1
vote
1
answer
32
views
Avoiding loops in Solidity for a simple situation
Suppose I have a pool that contains some coin say ETH. Imagine there are 100 users that benefit from this pool and I want to keep track of how much ETH in that pool is allocated to each user. When new ...
0
votes
1
answer
28
views
Eth price dont update after another function iteration
Hi i have an issue i created a function that fetches prices from dex.This is looped every 5 sec and the prices should be up to date every 5 sec.The issues start because the price refreshes every few ...
0
votes
0
answers
21
views
Javascript FundMe Solidity Test code troubleshooting
Code 1 returns error while Code 2 doesn't, why?
CODE 1
const { assert, expect } = require("chai")
const { ethers } = require("hardhat")
describe("FundMe", function () {
...
1
vote
2
answers
52
views
Implement smart contract that can spend user's tokens with just one approve
I am looking for a way to implement smart contract that can spend user's ETH or erc-20 tokens with just one approve, without anything else required from user.
USECASE
1.User approves token spending(...
0
votes
1
answer
52
views
My swap smart contract doesn't seem to swap the tokens
I have made a smart contract on Avalanche Fuji chain to test swapping tokens. When I call the smart contract on Remix, my AVAX gets sent, but I never get the USDC I am supposed to get for my AVAX. I ...
1
vote
1
answer
26
views
Using .call to send funds to Smart Contract Wallet account
I have the following function in my smart contract which fails to send funds to a Smart Contract Wallet (SCW). It works fine with standard accounts. I explicitly set gas to 0 because this is an ...
1
vote
2
answers
67
views
What's the best way to raise a number to the power of a fractional exponent in Solidity
I am trying to raise a number to a fractional exponent in solidity. I have tried using the Bancor (https://github.com/bancorprotocol/contracts-solidity/blob/v0.3.1/solidity/contracts/BancorFormula.sol)...
0
votes
0
answers
42
views
Spot the problem in the contract of the unsellable token
I am currently trying to understand how the smart contracts work. I have bought a tiny amount of a token that I suspect to be honeypot and indeed it is unsellable, PancakeSwap gives the error: ...
0
votes
1
answer
26
views
revert: No run-latest.json file found for specified chain
here is my integration script.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import {Script, console} from "forge-std/Script.sol";
import {DevOpsTools} from "lib/foundry-...
0
votes
0
answers
251
views
A little help with the Uniswap V3 flash loan arbitrage code
I'm trying to use flash loans on Uniswap V3 to trade across different pools (two of these four: 0.01%, 0.05%, 0.30%, 1.00%)
I've tried running codes from multiple tutorials:
https://solidity-by-...
0
votes
0
answers
21
views
Safely converting 1 WEI to the current ETH/USD Chainlink price
Let c be the current floating point price of ETH/USD precise to 8 decimal places.
Since Solidity cannot store floating points, getting the current price of ETH/USD from Chainlink's data feed returns c ...
1
vote
0
answers
87
views
SignTypedData in ethers version 6.9.0
Does anyone know how to perform signTypedData in ethers version 6.9.0 . I am tryin to do this but it reverts with this function doesnt exist . I am trying to create a signer usin g JavaScript ...
0
votes
1
answer
102
views
How to decode storage value of a struct
On Uniswap V3 Pool contract, we have slot0 struct which is located on slot 0 of the storage
struct Slot0 {
// the current price
uint160 sqrtPriceX96;
// the current tick
...
0
votes
2
answers
29
views
Solidity array not updating correctly
My contract has structs for products, companies etc. The product struct has a 'quant' var to store quantity of the product ordered, and an array of quant size called clicks, that's supposed to track ...
1
vote
2
answers
122
views
Foundry Test for a function with array of structs
I have this foundry function and I don't have any idea how to pass an array of structs to batchList function
function test_ListMockERC721() public {
vm.prank(add1);
erc721Mock.mint(msg.sender);...
0
votes
1
answer
19
views
What does decimals/fungible token normalization mean? I need help with mitigating precision loss
What is the code to convert them to correct decimals without precision loss?Does it mean that you should make all the token decimals to a certain standard of the protocol? Let say 18?
If Token A is 16 ...
0
votes
0
answers
40
views
Geth still stucking at synchronizing
I trying to run my eth mainnet node using Geth and prysm but synchronizing process still stucking.
Error:
INFO [12-05|02:29:14.015] Syncing: state download in progress synced=0.36% state=961....
1
vote
1
answer
20
views
Can Chainlink time-based upkeep register multiple cron jobs in a single contract?
I have been trying to make a raffle platform with the Chainlink automation.
I can see the time-based upkeep can have only one cron job,
But when the raffles are created in the platform, each of them ...
1
vote
0
answers
26
views
Is NFT swap possible on cross chains?
I have done a bit of research on this, and I have found only the same chain NFT swap but I want to know the different chain swapping b/w two users, Please provide some links or guidance to achieve NFT ...
0
votes
1
answer
17
views
Im trying to build a cryptocurrency(USD tether just like USD) that works with ethereum and polygon,
I happen to be relatively new to block chain, have an understanding of PoW and PoS, I'm learning Solidity at the moment, I'm supposed to design thi cryptocurrency that is compatible with ethereum and ...
0
votes
0
answers
8
views
Not able to fetch correct APY in aave mumbai
I am following this doc - APY and APR - Developers to fetch lending and borrowing rates in mumbai for usdc but they doesn’t seem to be correct and are different from aave staging UI, how can I solve ...
0
votes
1
answer
27
views
Solidity - Function Selector Loading onto the stack: why DIV instead of SHR?
I'm currently learning about how the function selector is loaded from calldata. The algorithm is like so:
PUSH4 ffffffff
PUSH29 0100000000000000000000000000000000000000000000000000000000000000
PUSH1 ...