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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
16 views

How to Test Solidity Struct in Args?

I have an event, where I forward a Struct when issuing it. But I'm not able to test this with chai + hardhat, I get the following error: Here is my getResult function, my struct, and my emitted event ...
1 vote
1 answer
27 views

Hardhat and Chai testing : How should I write the test?

I've digged through all the related question, but none of these worked for me. I used this repo, and replaced the contract and test file : https://github.com/NomicFoundation/hardhat-boilerplate EDIT ...
0 votes
1 answer
9 views

A Problem with the index of an array of smart contracts in Solidity: Expected constant integer error

I am totally new to solidity and not sure how different data types are used. I am writing a code that handles an array of smart contracts, read and store values in them etc. In one function (...
  • 3
0 votes
0 answers
9 views

Calling chainlink VRFCoordinatorV2.sol contract from a local hardhat network (Goerli fork)

The goal is to work with the real VRFV2Coordinator contract: https://github.com/smartcontractkit/chainlink/blob/e1e78865d4f3e609e7977777d7fb0604913b63ed/contracts/src/v0.8/VRFCoordinatorV2.sol That is ...
  • 1
0 votes
0 answers
13 views

Reverted Transaction For Any Adress (require not functioning as intended) in Solidity

I'm in the process of making a decentralized polling web app (relatively new to smart contract development). The idea is that a user connects their wallet via MetaMask, creates a poll or votes on a ...
0 votes
1 answer
12 views

How to get the exact block number in Hardhat deploy script?

I have written a code in hardhat deploy script to fetch the exact block number at which the contract has been executed, but it usually returns the block next to the original. Any idea how to get the ...
0 votes
0 answers
9 views

Typechain and @typechain/ethersv5 conflicting issue in hardhat

I am trying to write test cases in hardhat using Typescript and Typechain. But when I try to compile the contracts using npx hardhat compile, it is asking me to install @typechain/ethers-v5. When I ...
0 votes
0 answers
11 views

Retrieving incorrect Address during Truffle Test?

Im practicing truffle tests after moving from hardhat. I began with a standard 721 like so: // SampleNft.sol pragma solidity >=0.4.22 <0.9.0; import "@openzeppelin/contracts/utils/Counters....
  • 111
0 votes
1 answer
47 views

reverting direct transfer with onERC721Received

Working on a NFT marketplace I want to disallow direct transfers, to only allow transfering through this contract's custom function createSale() Here is the way I came about: function ...
  • 165
0 votes
0 answers
13 views

Delete an array element by its value in solidity (and check its existence)

I have an array in solidity which holds addresses. address[] public holders. Now, I have to delete an address based on the value provided. I also need to check the existence of an address to make it ...
1 vote
1 answer
24 views

What does this balanceOf function do?

function balanceOf(address account) public view override returns (uint256) { if (_isExcluded[account]) return _tOwned[account]; return tokenFromReflection(_rOwned[account]); } Does the ...
  • 11
0 votes
1 answer
16 views

Adding ERC2981 Royalties to an ERC721 Contract

I just added the ERC2981 Royalties Contract to my ERC721 Contract but while doing so noticed there's no way to actually retrieve the Royalty % for any specific Token. The ERC2981 contract simply doesn'...
  • 897
0 votes
0 answers
21 views

Convert bytes signature into string

I am storing a signature in my smart contract sort of like this: bytes private mySig; function saveSignature(bytes memory sig) { mySig = sig; } Using ethers, I can call saveSignature with the ...
  • 579
0 votes
1 answer
21 views

Warning: This declaration shadows an existing declaration

Can you please help me out with this code, where I get the six warnings shown bellow? As a result, the withdrawal doesn't go through with the specified amount. But I don't know how to get around it. ...
0 votes
1 answer
28 views

How to make sure that a contract's interface and functionality isn't lost after converting it to byte code?

Since Ethereum contracts are stored on the blockchain as byte code but people will want to understand how to interact with contracts, I wonder if there is enough information stored about contracts on ...
0 votes
0 answers
7 views

Wrap LP tokens + Rewards Yield in One Token

My question is whether there's any contracts out there currently that will allow you to wrap LP tokens + Reward (incentives) yield in the same token contract. Essentially, we have an LP token + ...
1 vote
1 answer
31 views

How to loop through mapping in solidity with least gas cost possible?

I have a mapping defined in my contract like below. mapping(address => uint256) public stakers I need to loop through it to get all of them for my frontend and other contract. function getStakers() ...
0 votes
0 answers
15 views

Crowfund Contract - Hardhat deploy Scripts- Help needed?

So i have followed this tutorial that creates a CrowdFund contract. In the tutorial he also creates an ERC20 token that gets deployed. And then that contract address is passed into the constructor of ...
0 votes
0 answers
12 views

Reentrancy attack (contract calling external contract to transfer funds)

So basically we have the code of some Curve pool (it's already rugged, just wonder if it was protected against reentrancy). Users deposit their curve pool tokens to this contract and it's locked for ...
0 votes
1 answer
18 views

send tx fee with msg.value

Hi I want to send 1% additional fee with msg.value but it's not working.... I tried to solve but I can't know the reason? What is the wrong point of my code? contract Trading { address public ...
  • 1
0 votes
0 answers
11 views

How we can store the data inside a struct while doing batch minting in smart contract

i am trying to store the data inside a struct , while batchminting struct batchMinterDetails { uint256[] tokenids; uint256[] amounts; uint256[] royaltyFee; address ...
1 vote
1 answer
19 views

Contract to check if sum of uint8 exceeds type(uint8).max

Hi I am a bit of a newbie in solidity, for a school exercise I need to compute the following contract: contract mySolution { function sum(uint8 x, uint8 y) external pure returns (bool, uint8) { // ...
  • 11
1 vote
1 answer
49 views

How to test a contract with multiple wallets?

I would like to generate N wallets with ether, using ethers. After that, I would like each of these wallets to interact with the functions of the contract. How can I do this? TEST describe("Vote ...
0 votes
0 answers
9 views

ERC20 token smart contract balance

I am doing my research on meme coins that do nothing other than just letting people to gamble their crypto, and when going through the code I found some lines that are not clear to me. Let's take this ...
-1 votes
1 answer
18 views

NFT with custom data structure

I want to mint nft with a custom structure : 1 ipfs link to a png image 1 ipfs link to a xml file 1 ipfs link to binary file 10 key/value pair How can i do that ? can i use erc721 or use other one ? ...
0 votes
0 answers
2 views

I am facing issues with pinata upload, please could anyone help me?

Is there a problem with this code? const axios = require('axios'); const FormData = require('form-data'); export const uploadJSONToIPFS = async(JSONBody) => { const url = `https://api.pinata....
1 vote
1 answer
19 views

Compiled smart contract successfully but when I try to deploy it to goerli nothing happens

I'm working on a tutorial project and complied my smart contract successfully but when I try to deploy the contract I get 2 warnings from node and that's t, no error or any message or anything, the ...
0 votes
1 answer
10 views

Unreachable code when calling an inherited assembly function in Solidity

Compiling the code contract Bar { function blockingFunction() public pure returns (bool) { assembly { return(0,0x20) } } } contract Foo is Bar { function foo(...
  • 165
0 votes
0 answers
10 views

Polygon-Ethereum bridge speed

I want to bridge between ethereum and polygon like this: There is a contract on the blockchain Polygon: contract Storage{ uint snapshot; function NewSnap(uint data) external{ snapshot ...
-2 votes
0 answers
8 views

Please help me with this error message

I am getting this message while trying to upload a NFT on my platform. Please help.
1 vote
1 answer
62 views

Hardhat testing - Error: Transaction reverted without a reason string

I'm new to coding and solidiy - I'm trying to test a covered-call option smart contract in hardhat but keep getting a transaction reverted error when I try to test the transfer of ether into the ...
  • 11
0 votes
0 answers
12 views

Unreachable code after an inherited function call in Solidity

I have a large auto-generated contract // SPDX-License-Identifier: GPL-3.0 /* Copyright 2021 0KIMS association. This file is generated with [snarkJS](https://github.com/iden3/snarkjs). ...
  • 165
0 votes
1 answer
36 views

How to create a stable swapping pool between and BEP-20 token and BUSD

i am working on a task in which i need to swap a BEP-20 token with BUSD. while swapping of after swapping their price should remain stable up 1 dollar , with min slippage. on which platform did i need ...
0 votes
0 answers
13 views

Array Index Out Of Bound/Negative Index In Ethers/Solidity

Relatively new to smart contract development. I'm writing a small app for decentralized polling with ethers.js and React. Where users can submit a poll and vote on other polls that people have created....
0 votes
1 answer
28 views

Defining large constant arrays in solidity

I want to define a large array, hardcoded into the smart contract. I know there's not currently a way to define a constant array in a smart contract and there has to be a getter function implemented, ...
  • 165
0 votes
0 answers
13 views

Please help me understand this error message?

What does this error message means? I cannot understand it.
0 votes
1 answer
27 views

How is struct data stored in blockchain?

I have written a simple blog post contract in solidity. contract Blog { uint256 counter ; struct BlogPost { uint256 id; string title; string content; address ...
0 votes
0 answers
13 views

Testing solidity contract with hadhat gives error missing argument even if i pass all valid arguments

Everything is working fine if we remove the array of addresses which is the last parameter in my function call. I have 14 parameters in my contract and if I am passing 14 parameters, Then also it ...
1 vote
1 answer
22 views

How to customize call() to send custom ether value?

I'm writing a contract & trying to implement a small fee for a feature when users trade NFTs & I'm getting errors everything I add a custom uint256 the transaction completely fails as such. ...
0 votes
1 answer
23 views

Stablecoin as basic ERC-20 Token

I am just trying to make a collateral backed stablecoin (1:1 AUD transparently backed) and am struggling to find any reasons as to why it cant be implemented using a simple ERC-20 contract? If I offer ...
0 votes
2 answers
32 views

Hardhat - how to Verify a Contract

I've successfully deployed an ERC721 contract to GOERLI using Hardhat - and the contract is working perfectly, but when I try to verify the contract, I keep getting errors. I'm wondering if it has ...
  • 897
0 votes
1 answer
24 views

How to convert staticcall result from bytes to a string array?

I've been able to use staticcall to retrieve values from smart contracts based on the name of a parameterless function, like this: bytes memory bresult; bool success; (success, bresult) = address(this)...
  • 579
1 vote
0 answers
17 views

Solidity assembly code - calldatacopy, delegatecall

I have been trying to understand how assembly code works,spending lots of hours, but I could not. Please help me Basically, I am digging into a proxy contract, and I do not really understand ...
  • 125
1 vote
2 answers
26 views

What is the return value of this asembly code?

Taken from this repository /// @notice Generate number function asmbl() public view returns (uint8 b) { assembly { let c := add(27, 16) mstore(0x80, c) { let d := add(...
  • 125
1 vote
1 answer
75 views

What is the return value of a function that has not defined a return value?

The code is taken from this smart contract /// @notice Only the central admin should be able to store his life memory in bytes32. function store_me_on_chain(bytes32 _data) public returns (...
  • 125
0 votes
1 answer
22 views

How to make data processing out of blockchain?

Is it possible to send data out of chain, process it and feed into smart contract without using centralized services? My goal is to make data processing large data decentralize (without using web2).
  • 1
0 votes
1 answer
16 views

No events emitted when running test in mocha

Good day, I'm new to blockchain and doing a university project. my contract file seems to be compiling but all my test cases are failing, saying no events emitted. I've included the test case and ...
  • 1
1 vote
1 answer
34 views

Discrete staking rewards with linearly increasing stake

Description I am implementing a Staking Pool of ERC20 tokens. Users can deposit any number of tokens, but only until a predefined block number when the staking actually starts. They do not earn any ...
  • 21
0 votes
0 answers
21 views

How to calculate the buy/sell fee or tax on the pairing token within the erc20 token - solidity

I am trying to develop an ERC20 token that has a marketing fee/tax for both buy and sell. The marketing fee/tax must be calculated and paid in USDC which will be paired with my ERC20 token on the ...
1 vote
1 answer
23 views

How does opensea exactly picks up the base URIs and what happens if I update it?

I was trying to create an ERC721 contract with an upgradeable URI method (to help the inclusion of extra NFTs in the future). I created the contract and minted an NFT. After that, I updated the ...