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
2answers
17 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
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
16 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
138 views

How to share TypeScript code between truffle tests?

I have some code in my TypeScript tests, say: function foo() { return 'bar'; } which I'd like to share with all my tests. The simple solution is to copy the function into each *_test.ts file. ...
0
votes
1answer
5 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
2answers
38 views

I am running my tests in the hardhat environment but it gives me 0 passing all the time

I am facing rather unusual behavior from hardhat. I have written my test cases in a file inside test folder when i run yarn teston the terminal it gives me 0 passing. Don't have any idea as to why it ...
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 ...
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
1answer
279 views

Can I set fixed gas price to Opensea-js fulfillOrder method

I am trying to use openseajs library's fulfillOrder method to buy NFT token. And I want to adjust the gas price to prioritize my transaction. Below shows how I do this. I pass the tokenId, ...
2
votes
1answer
370 views

Arrayify error, when passing a string as an argument to a transaction

I have been having this problem with the web3 library for a while now and I am not sure how to solve. I am encoding a transaction within a react app. So far, all contract interactions inside the app ...
0
votes
1answer
11 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
1answer
21 views

Why can't I see my updates I made with truffle test in ganache?

making my first steps in blockchain technique I picked the most simple example SimpleStorage I'm using truffle and ganache. I coded the contract simple_storage.sol: // SPDX-License-Identifier: MIT ...
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 ...
1
vote
1answer
30 views

While writing a test using dapptools, how do I send a transaction as a specific wallet address?

I'm playing around with dapptools: dapp And I want to write a test that checks the gas for OpenZeppelin's ERC721 implementation of the transferFrom(..) function. Here's my test: // SPDX-License-...
4
votes
1answer
4k views

Where are strings stored in Solidity?

I wonder where strings are stored in Solidity? Especially, where are string literals, function arguments, and variables stored? I recall, I've read that strings cannot be saved to memory, but is ...
0
votes
0answers
8 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 ...
1
vote
2answers
520 views

Get hash transaction by your encode input data

In my application i must follow the use case: I need to record any document hash on the Ropsten (eth testnet) blockchain. The hash is unique and i'm using a mapping in my smart contract to accomplish ...
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
11 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-...
1
vote
3answers
487 views

Hardhat Test returns transaction instead of return value

I just came from truffle to hardhat. Like the title says, I have a return value (address) of a contract and getting the transaction back. Any idea what I can do about that? it("Check all tested&...
6
votes
2answers
5k views

get the return value of payable function?

Let's say there's a payable Solidity function function doSomething() payable returns(uint) { require(msg.value == 1 ether); return 1; } And you call this function instance.doSomething({ ...
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
6 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-...
1
vote
1answer
126 views

How to call .increaseAllowance() from another token

I'm deploying a contract that is the owner of a token. In that contract i want to say that the token increaseAllowance to msg.sender and the amount that msg.send have putted in arguments of the ...
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 ...
3
votes
1answer
595 views

Full Integration Testing smart contracts

What is the most agile way to fully integration test smart contract code? I've seen people use shell, etc. Is there a golden standard somewhere?
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,...
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
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/...
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 ...
4
votes
1answer
1k views

Sending string to deployed contract function

var source = fs.readFileSync("./vote.sol", "utf-8") var compiled = web3.eth.compile.solidity(source); var abi = compiled.identify.info.abiDefinition; var Vote = web3.eth.contract(abi); var ...
23
votes
2answers
21k views

How to pass arbitrary bytes to a function in Remix (2017)

According to this question I could write a simple contract like: contract SimpleStorage { bytes input; function setInput(bytes enterBytes){ input = enterBytes; } } Using "0x1234" as a ...
0
votes
1answer
12 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,...
1
vote
1answer
21 views

Forwarding Ether from one contract to another

I am currently try to write two smart contracts. Here is the first one: // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; contract Token { mapping(address => uint) ...
1
vote
2answers
261 views

web3.js not working with React JS

I have installed web3.js npm install web3 my App.js import React , {Component} from "react"; import web3 from "web3"; import detectEthereumProvider from '@metamask/detect-provider'...
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 ...
2
votes
2answers
2k views

Do Solidity smart contract symbols support unicode?

In a smart contract where the token name and symbol are defined, is unicode supported or should these be ASCII only characters? As below, would it be a valid contract or token symbol? constructor()...
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 ...
1
vote
2answers
91 views

solidity mapping does not persist

solidity mapping does not persist I have this solidity code contract Starting { //pragma solidity ^0.6.12 struct itemStatus { bool created; } mapping (bytes => itemStatus) ...
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 ...
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 ...
0
votes
1answer
131 views

No contract at given address

I deployed a contract on a private network and it worked but all of a sudden it stopped working for reads only writes still succeed. I get no contract at given address. Below is my call of the ...
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 ...
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
272 views

Error: The contract code couldn't be stored, please check your gas amount during deploy

I know this issue was discussed before several times, but I cant get the solution to my problem. I'm trying to deploy a contract with Truffle on Ganache. During the deployment in 2_deploy_contracts....
1
vote
2answers
255 views

How could I convert uint type to bytes type in solidity?

I want to convert uint type data to bytes type in solidity. I've found a answer about this which is like below. function toBytes(uint256 x) public pure returns (bytes memory b) { b = new bytes(32)...

1
2 3 4 5
257