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

I get error saying "invalid contract address or ENS name" when I try to run Interact.js script from Alchemy's Hello world smart contract tutorial

I was following This tutorial from Alchemy to build a HelloWorld smart contract. After successfully deploying it to alchemy, when I wrote the 'Interact.js' script from the tutorial and tried to run it,...
0
votes
1answer
6 views

Is downcasting safe in Solidity?

So I am currently implementing a Hash-Time-Lock using a given Interface for my contract. The interface requires to give a duration as a uint(256) but then wants the produced deadline (duration + block....
0
votes
0answers
2 views

Calculate interest rate percentage with variable ERC20 decimal values

I have multiple ERC20 contract that implemented different decimal values: 18 decimal places (e.g., Basic Attention Token) 8 decimal places (e.g., Comp Token) 12 decimal places (e.g., Roger Token) ...
0
votes
1answer
7 views

Solidity: recover address from hashed message

I recently was going through some sol contracts, because I am planning to create my own one. So I stumbled upon this function call: function tryRecover(bytes32 hash, bytes memory signature) internal ...
0
votes
1answer
17 views

Web3.js. How to get returned value when the transaction takes minutes to be mined

I have a solidity contract with a method that mints an ERC721 token and returns the tokenId function createItem(string memory tokenURI) public returns (uint256) { _tokenIds.increment(); ...
1
vote
1answer
9 views

How to implement indexOf in solidity?

In javascript, can use indexOf to get the index of the value. const array = [2, 5, 9]; const index = array.indexOf(5); How to implement it in solidity? I'll get the value from another function, and ...
0
votes
1answer
13 views

Safetransfer Vs transfer

Does anyone know the difference between safeTransfer and transfer in ERC20? People said that safeTransfer returns boolean, which is much safer than "transfer"? I do not understand it well, ...
0
votes
0answers
9 views

Correct way of randomly selecting token Ids from already minted NFT's

I have an NFT project with 1000 NFTs. As part of my project, users who hold an NFT will be entered into a lottery. The function I want to implement is the following: Select x number of users to ...
0
votes
0answers
9 views

How to write Test case for NFT buy functionaity?

Function for buying NFT function buy(address nftContract, uint256 itemId) public payable nonReentrant { uint256 price = idToMarketItem[itemId].price; uint256 tokenId = ...
0
votes
0answers
12 views

Can not verify contract (can not match byte code) on etherscan.io (mainnet)

We are trying to verify our smart contract code on mainnet but are unable to do so. We followed this tutorial, although we are using an older version of the code: https://medium.com/bitfwd/how-to-do-...
0
votes
0answers
7 views

Solidity Brownie pytest - tests are failing when connecting to ETH forked mainnet but work when running locally

I'm working through FreeCodeCamp.org's YT Solidity tutorial and I'm up to the part where I'm trying to run pytest on an ETH Mainnet Fork. When I run the tests using brownie test --network mainnet-fork-...
0
votes
0answers
31 views

HI, im a beginner solidity coder in an internship/training with a blockchain startup. I was tasked with a lottery contract that im having trouble with

Make lottery smart contract Entry fee 25000000000000000 Duration: Every 10 Minutes ○ 50% Winners and 50% Losers ○ Winner Gets 1.8X ○ Losers gets 0X I have come up with the following code //SPDX-...
0
votes
0answers
9 views

What to pass for abi encoded arguments

I had cloned usdc contract on polygon test network and deployed it. I want to test deposit method but couldn't able to figure what to pass in depositData( more specifically in which format should i ...
0
votes
0answers
4 views

How to make function selector of the function from another deployed contract

I want to make the function selector of a function that is being interacted from another deployed contract. My code goes like this... interface Ierc20 { function mint(address to, uint amount) ...
0
votes
0answers
4 views

Declaration Error when pushing data to nested struct

I'm trying to push data to my nested LoanTerms struct. However, I can't seem to figure out how to make this particular line work: loanTerms: loanTerms.push(LoanTerms(currency, principle, interestRate,...
0
votes
0answers
4 views

Does brownie have functionality to analyze gas costs for all function calls?

Does brownie have any sort of functionality that gives a breakdown of the cost to deploy all contracts and execute all function calls within a brownie project with min, max and average gas cost ...
0
votes
0answers
6 views

How to use Proxies and UUPS

I can't understand how to implement UUPS proxies. Should I create another proxy contract for this contract: // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/...
1
vote
1answer
24 views

How to pass array of addresses while testing the contract

I've written a contract... contract TimeLock is TimelockController { uint256 minDelay = block.timestamp + 4 minutes; constructor( address[] memory proposers, address[] ...
0
votes
1answer
13 views

How to check If the smart contract support an interface?

I have token contract which implements IERC2981 interface and I've overridden the supportsInterface function like so. function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721,...
2
votes
1answer
15 views

delegatecall in Brownie

I am trying to perform delegatecall in Brownie solving the Delegation task in the Ethernaut app in order to claim ownership of the Delegate contract (see below). What is the equivalent of the ...
0
votes
0answers
15 views

Best way for a smart contract to be approved to transfer tokens from a different ERC20 smart contract to an address

I have two smart contracts; tokenContract otherContract tokenContract is an ERC20 contract with a fixed supply of tokens. otherContract is a separate contract that users of our application interact ...
0
votes
0answers
4 views

Are there benifits using Moralis node provider services?

I'm very new to solidiy and blockchain so forgive me if this is a stupid question! I've been playing around on the BSC test net, following a few online guides and the Binance dev docs. I've noticed ...
0
votes
1answer
13 views

Transferring a value into a fallback function of a contract

I'm trying to figure out what happens when you send a value to a contract. If the destination address (to) is a contract, then the EVM will execute the contract and will attempt to call the function ...
0
votes
0answers
5 views

Nothing returned from `truffle develop` command on powershell

I'm new to web3. I'm trying to deploy a smart contract to the Ganache core ETH development node using Truffle. However, when I ran the truffle develop command, the console is stuck and does not do ...
1
vote
0answers
8 views

Decrypting data on chain and verifying the decryption is correct

I already know decrypting data on chain will reveal the key and the plaintext to everyone and for my use case that is exactly what I want. I want to be able to build a contract that has a pre-...
0
votes
1answer
15 views

Using payable functions in the remix ide

I created a simple solidity contract in the remix ide. I cannot figure out how to test the payable functions I created. here is an example of a payable function: function pay() payable { } here is a ...
0
votes
2answers
28 views

How to transfer my ERC20 token correctly?

I have my ExampleToken contract from Openzeppelin: // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.7; import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/...
0
votes
0answers
10 views

How to prevent MEV Bots "attacks" to a fork of uniswap V2

I deployed a smart contracts structure to create a DEX in the mainnet. Is a fork of UniswapV2, only changing the variable names. I added some liquidity to it and it worked well. After some days, we ...
1
vote
1answer
42 views

Detect receiving token address in "receive() payable"

for the given receive function , is there a way I can detect the receiving tokens address (Detect what coin my contract is receiving ) is it possible to extract this information from msg ? receive() ...
0
votes
1answer
19 views

Need help with checking responses from balanceOf functions

So I have two contracts Contract A & Contract B Contract A is an ERC721 that allows for the balanceOf function to be called after passing it an address. It will return response of how many NFTs ...
1
vote
0answers
24 views

How to change/set values of a mapping through a function in solidity?

I have the following structure, with the mentioned mapping struct A { uint a; bool[100] b; } mapping(uint => A) public arr; I am using this function to set/...
1
vote
2answers
21 views
+50

What are the pros and cons of emitting events vs return statements?

According to this answer the return data of a smart contract function call can be accessed, however the same return data can be collated into an event to emit, so when should either method of ...
1
vote
1answer
19 views

How to add back default Rinkeby Testnet network in brownie networks list back?

I accidentally deleted the default rinkeby network that comes with brownie and wanted to know how to add it back? I tried with the below cmd by creating an infura project but I'm getting the ...
0
votes
2answers
20 views

how to write a contract to set a reward for players and they claim the reward?

I want to create a contract to give the players rewards and they claim their rewards. It seems everything is ok! // SPDX-License-Identifier: MIT pragma solidity ^0.8; import "@openzeppelin/...
0
votes
1answer
13 views

Does stack persist through external calls?

Looking through the docs I found that a malicious caller can take the stack depth to ~1000 and then make a call which would fail due to stack depth. Based on that let's assume that stack indeed ...
1
vote
1answer
13 views

Why is it necessary to access smart contracts via their address?

I am new to solidity and just started exploring smart contracts. I have a smart contract for creating a Person struct with name and age and a function to access the structs using the name variable: ...
0
votes
1answer
13 views

Clone factory contract variable initialization

DaoRegistry dao = DaoRegistry(_createClone(identityAddress)); _createClone() returns a payable address, but the DaoRegistry constructor is empty. I haven't been able to find an explanation for what ...
1
vote
0answers
8 views

What are the consequences of a nested mapping?

I'm wondering what the consequences of using a nested mapping are. If I have a mapping that is 4 levels deep, for example: mapping(address => mapping(address => mapping(uint256 => uint256))) ...
0
votes
1answer
16 views

How to convert default two's complement representation to sign magnitude form?

According to this answer the EVM by default uses two's complement notation for handling signed integers. However for my application I would like to work with the sign-magnitude representation where ...
0
votes
0answers
9 views

Bond Price Formulas in Olympus DAO

In the OlympusDAO solidity smart contracts, the usage of several numbers confuses me. bondPrice(): The bond price is calculated using the formula: price_ = terms.controlVariable.mul( debtRatio() )....
0
votes
1answer
11 views

Ownable function call from another function

I have two ownable functions (I'm using openzeppelin), when I invoke the second function from the first one, I get: "Ownable: caller is not the owner". function first() external view ...
0
votes
1answer
9 views

Solidity: Storing and returning array in struct

Trying to store array directly in a struct however when I call the struct the array is not returned. Not sure whether this is just a return problem or a storage problem? struct LockRoundData { ...
0
votes
0answers
31 views

Why I can't push items into this array?

it's very tricky, when in the truffle , I call f(),it can't push an item into addressArray.(console.log(addressArray[0]) always unidifined)) but when I use Remix, it worked. pragma solidity ^0.6.6; ...
1
vote
2answers
23 views

How to get status of a Transaction in Solidity from within the contract itself

Is it possible to get the status of a Transaction like if it went thru fine or any failure, within a smart contract function itself. lets say, I am trying to transfer some ether to a different address ...
0
votes
0answers
13 views

How ERC721 NFT accept payment from ERC20 token instead of ETH [closed]

I have created my own ERC20 token already (1 year ago). Today, i try to deploy the contract of ERC721 token for NFT marketplace. by this git After i deployed above git following by the tutorial ...
1
vote
1answer
21 views

Keeping the smart contract data when switching networks

Hello guys so im making a project that is going to run 1 month on the rinkeby test network but after it will switch to mainnet. The problem is that I would like to keep the contract data from the ...
1
vote
0answers
10 views

What's the point of 'assert'? Can't i just use 'require' all the time? [duplicate]

I read this stackexchange post and understood the difference between 'assert' and 'require'. But it got me thinking, what even is the point of 'assert'? I mean it has same the behaviour as 'require' ...
0
votes
1answer
14 views

How to start with writing Upkeep for the function in my smart contract which concludes an auction?

I've just started learning about Chainlink Upkeepers, I'm very new to this and not able to plan my approach how to begin with automating the concludeAuction() function below. The smart contract ...
0
votes
0answers
6 views

| ^ (Relevant source part starts here and spans across multiple lines). this error had occured while complining how to correct it help me out [duplicate]

// SPDX-License-Identifier: GPL-3.0 pragma solidity>= 0.5.0 < 0.9.0; contract Identity { string name; uint age; constructor() public { name = "Prem"; age =24; } function getName() view ...
0
votes
0answers
13 views

external function solidity can receive struct?

In the most examples of external functions I can see that receive primitive types like uint or string and with this create instances of structs, but I don't see an example where an external function ...

1
2 3 4 5
257