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
4 views

How to give approval to all addresses to transfer my tokens?

I am trying to develop an erc 1155 marketplace? I am using the function : ERC1155.setApprovalForAll(to, true); To provide approval to all tokens that the owner owns to a particular address. Now, I ...
user avatar
0 votes
0 answers
7 views

Python bytes not being read into solidity bytes

I have this code for returning bytes from a python script: blockbounds is a list of integers component.length and component.color are both integers def buildBytes(): componentsToBytes = bytearray()...
user avatar
0 votes
0 answers
5 views

How would I link multiple tokens to a single token?

So I'm trying to allow a user to stake a token and have users stake their tokens from a different collection within that token if that makes sense. Kind of like storing cars in a garage. The contract ...
user avatar
  • 1
0 votes
0 answers
7 views

0x fillQuote fails on mainnet fork. i am sending a delegate call (i want to save transaction context) to the 0x proxy contract but transactions fail

function fillQuote( // The sellTokenAddress field from the API response. IERC20 sellToken, // The buyTokenAddress field from the API response. IERC20 buyToken, // The allowanceTarget field from the ...
user avatar
  • 1
0 votes
1 answer
9 views

Methods that only return arrays are very common. But, in the 'returns' argument, do I use memory or storage? and why?

// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.9; contract MyContract{ address[] public myAddresses; function getMyAddresses() public view returns(address[] [[...
user avatar
  • 3
0 votes
1 answer
8 views

How To Convert Hex String to A Uint in Solidity ^8.0.0

I have this function that converts a unit to a hex string: function uintToHexString(uint i) public pure returns (string memory) { if (i == 0) return "0"; uint j = i; uint length; ...
user avatar
  • 113
0 votes
0 answers
6 views

Storing addresses of all users deposits

I'm trying to allow all users to deposit tokens into my contract which I keep tracking of using a mapping mapping(address => uint256) public playerBalance; which is fantastic. But I later need to ...
user avatar
0 votes
1 answer
9 views

Iterating over a list of payable addresses throws error that "the value you send should be less than your current balance"

Stuck with this for a few days already, looking for some help. I write a contract that allows users to bet on a certain event and then once the result of the event is evaluated it should change their ...
user avatar
0 votes
1 answer
14 views

Where is the single-parameter version of function sub() defined in SafeMath?

I'm going through the Ethernaut challenges to learn Solidity, and in challenge 3 ("Coin Flip"), they show the following code which subtracts 1 from the current block number: I assumed that ...
user avatar
  • 105
0 votes
2 answers
7 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:
user avatar
0 votes
0 answers
7 views

can we call constructor in another function of the same contract in solidity?

can we call constructor in another function of the same contract in solidity ? Curious, Kindly reply asap. Thanks
user avatar
0 votes
1 answer
9 views

Understanding memory type solidity in function's return type

pragma solidity ^0.8.0; contract Crud { struct Users{ uint id; string name; } Users[] users; // this is type storage uint length = 0; function addUser(string ...
user avatar
0 votes
1 answer
7 views

mapped struct storage layout (slots) and collsions

I want to establish a pattern that ensures no storage slot collisions between current and future (compliant) versions of a contract behind a transparent proxy. In particular, contracts that are meant ...
user avatar
  • 50.6k
0 votes
1 answer
14 views

`should be marked as abstract` for a contract that inherits from ERC721Enumerable

I'm trying to understand why this very simple contract returns the error should be marked as abstract. I don't have this error when I don't inherit from ERC721Enumerable. pragma solidity ^0.8.0; ...
user avatar
  • 105
0 votes
1 answer
17 views

How to store a large mapping in a smart contract?

I have a contract that need to access the address of different tokens given their name as a string. I thought about doing the below: contract MyContract{ mapping (string => address) public ...
user avatar
0 votes
0 answers
10 views

How to Call a payable function I am getting error={"code":-32603,"message":"Internal JSON-RPC error.","data":{"code":3,"message":"execution reverted"}

I am trying to call buy function which is a payable function using metamask signer method. I am getting error for sending incorrect ether value. Here I have set the price as 1 which is 0x01 in hex ...
user avatar
  • 315
0 votes
0 answers
4 views

Deploy a crowdsale contract for a previously deployed ERC20 token

I have deployed an upgradable ERC20 token using ^0.8.4 and I would like to set up an AllocatedCrowdsale from OpenZeppelin for said token. I have set up a second project for the crowdsale using ^0.5.0 ...
user avatar
0 votes
0 answers
9 views

Uncaught Error: invalid BigNumber string (argument="value", value="2022-05-18", code=INVALID_ARGUMENT, version=bignumber/5.6.0)

I created a function that registers births and use a form to submit the data. The problem is every time I try to use web3/Javascript, it gives me this error. The error is because of the dateOfBirth ...
user avatar
0 votes
2 answers
24 views

How to get the returned values in Solidity functions? [duplicate]

Imagine I'm developing a simple function as the following: uint256 state; event Addition(uint256 result); function addition(uint256 a, uint256 b) public ...
user avatar
  • 584
0 votes
1 answer
14 views

address.transfer() fails, while address.call{}() works fine in reentrancy attack. Why?

I was trying to learn reentrancy attacks and how to save the contracts against them. I previously user address.transfer() to withdraw the amount, but the function reverted when performing the attack. ...
user avatar
0 votes
0 answers
14 views

How to fix `ParserError: Expected ',' but got '=>'`?

pragma solidity ^0.8.2; contract token { mapping(address => uint) public balances; mapping(address => mapping(address => uint)) public allowance; uint public totalSupply = ...
user avatar
0 votes
0 answers
8 views

How to create a external call instance function to truffle suite

Is there a way to instantiate a function of my contract, not using the truffle console but by creating a js file? if so, how do I do it?
user avatar
  • 1
0 votes
0 answers
16 views

How to Approve spend of one Token with Web3.js? [duplicate]

I am currently using an html (with javascript) page that is available to my users. I need to set up a button that allows the spending of BUSD or other stablecoin tokens on the same page. Once the ...
user avatar
0 votes
3 answers
39 views

Casting on solidity vs a constructor

I am looking at some sample code on Github and I don't know if what is to the left of the "=" is type casting or a constructor. I tried Googling this for 20 minutes but couldn't find an ...
user avatar
0 votes
1 answer
19 views

Call a function from another contract (by caller contract) [duplicate]

I need to call a function from another contract, but is it possible that the caller is the calling contract, and not msg.sender/wallet? For example contract BrainGame { function updateGameScores(...
user avatar
  • 103
0 votes
0 answers
5 views

How do I use Mapping as a filter to return specific values in my struct?

I have a struct in my smart contract, that stores tokens in two different statuses, either as an unassigned gifts or as an assigned gifts. I would like to configure my mapping as a filter to return ...
user avatar
  • 107
0 votes
2 answers
19 views

Send msg.value to another address immediately

Is it possible to implement a payable function and transfer msg.value to another address immediately? function purchase() payable public { //transfer msg.value } I'm thinking this wouldn't work ...
user avatar
0 votes
1 answer
11 views

Solidity return enum in library

library MyLib { enum MyEnum { A, B } function f() public pure returns (MyEnum){ return MyEnum.A; } } I want to return the enum in library. It is deployed as well, but ...
user avatar
  • 1
0 votes
0 answers
11 views

Presale inside token smart contract

I am planning on launching a token. We need liquidity and the way I am thinking of is to implement a presale. Is it a good idea to write that i side the token smart contract? Creating a mapping of ...
user avatar
1 vote
2 answers
37 views

Why using storage keyword instead of memory cost less gas?

struct User { bool isActive; uint256 userAge; } mapping(userId => User) public users; method 1; function example(uint256 userId) public { User memory user = users[userId]; bool ...
user avatar
0 votes
0 answers
9 views

How can I return struct/ structs based on date in timestamp?

I'm trying to make a get function based on date(in timestamp) Do I need another mapping? Take into consideration that it might be more than one registries on the same date. Any help is great. :) ...
user avatar
0 votes
1 answer
16 views

How can i store each address that interact with my smart contract?

i am working on a crowdsale type of smart contract and i want to store everyone who sent ether to my contract .So i created a struture like this struct User { address participantsAddress; ...
user avatar
  • 3
0 votes
1 answer
18 views

Comparison between contract type variable and address

How do you check if a contract mapping/variable is still to be initialized ? comparing contractTypeVariable != address(0) gives a type error Operator != not compatible with types contract BasicToken ...
user avatar
  • 329
0 votes
0 answers
18 views

Fixed length for dynamic arrays

Let me explain, I am creating a contract which will be storing about 1000 token addresses and the token prices. I am using an array like this. address[] internal assetList; I cannot create static ...
user avatar
0 votes
1 answer
23 views

from solidity: TypeError: Member "log" not found or not visible after argument-dependent lookup in type(library console)

from solidity: TypeError: Member "log" not found or not visible after argument-dependent lookup in type(library console). Im using hardhats lib "hardhat/console.sol"; I want to ...
user avatar
0 votes
0 answers
11 views

Is using block.timestamp + appropriate for adding months even years into the future?

I have a smart contract that is date dependent. Intended to schedule events far into the future, like days, weeks, months even years into the future. As long as the events happen on the specified date,...
user avatar
  • 107
0 votes
0 answers
13 views

How to Use 2 NFTS metadata to create a new NFT (Breed) with Metadata JSON that they choose from the 2 NFTs

How to Use 2 NFTS metadata to create a new NFT (Breed) with Metadata JSON that they choose from the 2 NFTs.
user avatar
0 votes
0 answers
5 views

Invalid ENS name in Damn Vulnerable Defi (naive-receiver)

I'm trying to solve the Damn vulnerable Defi challenge's Level 2 - Naive Receiver. We have to drain the user's balance by exploiting the missing access control allowing anyone to be the borrower and ...
user avatar
0 votes
0 answers
5 views

How to set price to NFT token and update that price?

I want to create a market place of nfts. I know how to mint and creat nft but I dont know how to set price of token, how to set list of orders. I read that the price should be set on token contract ...
user avatar
  • 101
0 votes
0 answers
34 views

How to Approve spend of one or many Token with Web3.js?

I am currently using an html page (with javascript) that is available to my users. I need to set up a button that allows the spending of BUSD or other stablecoin tokens on the same page. Once the ...
user avatar
0 votes
0 answers
8 views

Metamask doesn't connect to it's own localhost or hardhat localhost

Metamask doesn't connect to it's own localhost. I run a hardhat node from Mac. I know it's a known issue, but I've tried all available methods listed below. I tried installing older versions of ...
user avatar
0 votes
0 answers
4 views

why is the transferFrom function not able to send ether? I keep receiving an error in remix ide

pragma solidity ^0.8.0; library Balances { function move(mapping(address => uint) storage balances, address from, address to, uint amount) internal { require(balances[from] >= amount); require(...
user avatar
  • 17
0 votes
0 answers
5 views

Changing msg.value

Is there any way to change msg.value between calls (or delegatecalls)? For example: A --delegatecalls(msg.value=0)--> B -->delegatecall(msg.value=1) --> C where some logic would happen in B ...
user avatar
  • 265
0 votes
0 answers
4 views

How to get hardhat to give more detailed error messages?

I am trying to call some function from the smart contract and I am only recieving the error message Error: Transaction reverted without a reason string . This makes degubbing quite hard. Is there ...
user avatar
0 votes
0 answers
23 views

How do I set the allowance for ERC20 tokens in Foundry?

In the following minimum viable test I'm failing to mock the allowance so that the ReceiverContract can transfer ERC20 tokens. The expected use-case would be a user (=externally-owned account) ...
user avatar
0 votes
1 answer
15 views

Losing ETH due to floating point numbers problem

Is there a chance that a user can lose a fraction of ETH just performing normal transactions (addding money to a pool, sending it to someone)? I'm refereing to floating point numbers, I know there are ...
user avatar
0 votes
1 answer
19 views

Interacting with one smart contract to another ? , Multiple smart contract interaction ? , One contract calls to another contract ? Solidity

Interacting with one smart contract to another ? , Multiple smart contract interaction ? , One contract calls to another contract ? in Solidity. My questions are: How does a contract with each other ...
user avatar
0 votes
1 answer
25 views

fallback not executing

I have a test project with proxy pattern (fallback/delegate call). The purpose is to have upgradeable contracts. Here is the proxy contract: // SPDX-License-Identifier: MIT pragma solidity 0.8.13; ...
user avatar
  • 103
0 votes
0 answers
10 views

ETH: Failing to Swap Tokens in same txid when transfering from DEX

I am having troubles with the following scenario: I have written a simple token which takes buy & sell tax fees of 3%. (All Good) I want the fee to be immediately swapped for ETH in the same ...
user avatar
0 votes
0 answers
21 views

Encrypted Calldata

https://bscscan.com/tx/0x1b30d12030e384eea6c608f28c889eb945e5e80c880c2ebd648b88aea3187bd0 I have found an account that sends encrypted calldata to a contract and then contract makes swap on ...
user avatar

1
2 3 4 5
288