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.

5,321 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
15 votes
1 answer
996 views

Trying to compile example code from pyethapp tutorial

I am trying to follow this example: https://github.com/ethereum/pyethapp/wiki/The_Console However, at the point where I should compile the code, I get an error: In [34]: print c contract NameReg{ ...
TMOTTM's user avatar
  • 1,953
8 votes
0 answers
4k views

SushiSwap - Inner workings?

I've been trying out in the past few days SushiSwap and lately SashimiSwap Contracts & Frontend and while I'm still getting familiar with the code. It turned out to be quite a challenge to make it ...
Liberalite's user avatar
8 votes
1 answer
974 views

Natspec Commenting Style for Structs

Is there specific way to explain the variables of a struct using the Natspec format? I do something like: struct XYZ{ uint x; //Explain what it does uint y; } Is it this the right way for ...
Anshu Jalan's user avatar
7 votes
2 answers
1k views

Unit testing a Solidity Library function with a struct memory argument

I am trying to unit test a Solidity Library contract function using truffle and web3. My simplified Library contract looks like this: pragma solidity >=0.5.16; pragma experimental ABIEncoderV2; ...
dionyziz's user avatar
  • 168
7 votes
1 answer
328 views

String Input of three numbers (comma seperated) doesn't work in Remix

So when I try to put in three numbers as a String in a usual setter-method, it doesn't work. Does anybody know why? function test(string memory x) public view returns(string memory){ return x; }...
Floari's user avatar
  • 83
7 votes
0 answers
303 views

Can I `eth_call` a non constant function from javascript?

I know that I can't get the return value from a transaction (How to get values returned by non constant transaction functions?), and non-constant functions have return value because they can be called ...
Ismael's user avatar
  • 30.5k
6 votes
0 answers
115 views

Best way to store and verify data onchain for offchain data integrity?

I have a web2 application that stores some information in database rows, however, I would like to store this information on-chain for data integrity, particularly on polygon. What is the best way to ...
Neo's user avatar
  • 161
6 votes
1 answer
223 views

Why do these two Ethereum transactions have different gas usages? Can't explain it from the GETH EVM debug traces

Two USDC transfers in the same block, both between non-contract addresses. Both call the same smart contract function transfer() but used very different gas. Some differences I can explain (see below) ...
Normadize's user avatar
  • 161
6 votes
0 answers
189 views

Kademlia: How does Ethereum uses node discovery protocol to avoid sybil/eclipse attacks?

I want to describe a case that's not clear to me. let's say we have 10 peer validator nodes who reach consensus and agree to store some blocks on their chain. Let's say now that a wallet wants to sync ...
Panagiotis Drakatos's user avatar
6 votes
0 answers
193 views

Need help to understand storage costs

I have tried to implement a simple cellular automaton logic using two different ways to track the final state: Track every iteration in a multi-dimensional array. Store only the last two iterations. ...
spacemonkey's user avatar
6 votes
0 answers
687 views

how to decode/encode ipfs for contracts

It's known that IPFS can use 2 types of CID, v0 and v1. In my contract, I let users store bytes data parameter. They can store some simple text on it or even pass the ipfs hash. This question is about ...
Nika Kurashvili's user avatar
6 votes
1 answer
110 views

Deploy gas issue for require reason string

I found a strange case and didn't find out why. ... modifier onlyMaster() { require(msg.sender == master || msg.sender == developer, "caller is not the master"); _; } ... ...
webelf000's user avatar
  • 126
6 votes
0 answers
1k views

Why does Ethereum use JSON-RPC and not gRPC?

I am fairly new to networking protocols especially JSON-RPC and gRPC as they are not nearly as common in web development as REST. I was reading around and seems like gRPC generally performs better. So ...
RhinoBomb's user avatar
  • 161
6 votes
2 answers
13k views

can't verify contract on etherscan (But we were unable to locate a matching bytecode (err_code_2))

so i'm trying to verify a contract on rinkeby and ropsten... getting the same error of "Compiler debug log: Error! Unable to generate Contract ByteCode and ABI Found the following ContractName(s) ...
Justin Kwon's user avatar
6 votes
0 answers
754 views

solidity-coverage show 0% coverage

I'm trying to make a test coverage for MetaCoin. This is my package.json, truffle-config.js and .solcover.js: module.exports = { port: 8555, norpc: true, compileCommand: '../...
Катерина Белоцкая's user avatar
6 votes
4 answers
3k views

"Mock compiler : Source not found" Error in Remix online IDE

I haven't been able to compile any solidity code because of this error. How do I solve this problem?
Usen's user avatar
  • 61
6 votes
2 answers
2k views

Web3 Event Filtering timeout

This is the code I use to get all events from a certain contract. Solidity: event NewEvent(address indexed contractAddress, address newBOPAddress, address payer, uint commitThreshold, bool ...
Gigi's user avatar
  • 71
6 votes
2 answers
662 views

How to access dynamic list from web3?

In my application players can create and join games. I store every game in a mapping(uint => Game), and send out a GameCreated event whenever a game is created. My issue is efficiently getting a list ...
Warkgnall's user avatar
  • 106
6 votes
2 answers
2k views

Contract creation gas cost depends on code in library function?

I have a contract fooContract which is using a fooLib library, calling fooLib.foo(LibStruct storage param) The transaction cost to create fooContract seems to depend on the code in the fooLib.foo() ...
szerte's user avatar
  • 1,221
6 votes
1 answer
2k views

Solidity: How could I decrease gas usage of complex structs?

Struct is very expensive as labelled here: It seems extremely expensive when storing struct type. https://www.cryptocompare.com/coins/guides/what-is-the-gas-in-ethereum/: sstore 100 Paid ...
alper's user avatar
  • 8,395
5 votes
1 answer
510 views

web3j is not generating struct inside my solidity contract

I have a struct Question in my smart contract. After generating the java wrapper class of my smart contract using web3j, Inside the wrapper class Question is not recognized, looks like web3j is not ...
Shoaib Kakal's user avatar
5 votes
1 answer
149 views

Metadata not showing on opensea

I have a problem with a simple nft program i did in order to learn more about ERC721. this is the code: // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/...
Squallaz's user avatar
5 votes
2 answers
444 views

How would an nft marketplace structure their smart contracts to pay out "creator shares"?

This may be a noob question, but does any know how a market like Nifty or any similar nft marketplace actually implement paying a "creator share" or royalty back to the original creator ...
AdjunctProfessorFalcon's user avatar
5 votes
0 answers
1k views

bitwise multiplication to reduce gas cost

This is the multiplication method from the SafeMath library. /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * ...
smatthewenglish's user avatar
5 votes
0 answers
1k views

How to mimic abi.encodeWithSignature in web3?

I have the following function that I would like to test. function createPlanet(bytes memory _data) public returns (address) { emit ProxyCreated(planetImplementation); emit ...
James Dawson's user avatar
5 votes
0 answers
236 views

How can i do 2^0.3 (exponent below 1) using integers?

simple problem, but i can't seem to wrap my head around it in solidity. how can i do 2^0.3 (exponent smaller then 1) in solidity using integers. thanks in advance K.
Ксения Леонова's user avatar
5 votes
1 answer
691 views

Truffle test fails to call the base function, wants the override

I have an extended ERC20 contract with ERC827 functions, which are overrides of ERC20 with an extra callback parameter. I have these two pairs of base/override functions: Base: function ...
Andrey's user avatar
  • 1,147
4 votes
0 answers
311 views

Hardhat and foundry, contract bytecode different

I'm developing a contract in hardhat project. But now I want to write test by foundry. My problem is I'm using create2, but when running contract by hardhat and foundry they gave different addresses. ...
CT95's user avatar
  • 373
4 votes
3 answers
971 views

ERC-20 token approval fails if amount is close to maximum balance

So I am using Wagmi, which uses Ethers.js under the hood. I have to approve the router address first in order to buy the other token. It works when I use the exact or slightly greater amount than what ...
sanjay dev's user avatar
4 votes
0 answers
159 views

Why does Ownable.sol from OpenZeppelin rely so much on the use of functions?

I wondered why OpenZeppelin relies so much on the use of functions when, at first glance, they seem unnecessary for such elementary operations. For example, take the Ownable.sol contract. Why isn't ...
PensoGlide's user avatar
4 votes
0 answers
529 views

Block scoping in Solidity to avoid "Stack too deep error"

I have a quite big function with 16+ local variables which produces the infamous Stack too deep error. To handle this bad boy I have searched for the possible solutions and ended up using scopes. ...
rihekopo's user avatar
  • 316
4 votes
0 answers
438 views

Decode parameters on contract creation or constructor parameters

I want to decode parameters passed to contract constructor. Even if i used the ABI of the contract, it doesn't seem to resolve the parameters used. Here is the transaction trace out put https://gist....
bereket gebredingle's user avatar
4 votes
0 answers
555 views

Solidity sourceMap and opcodes. No map entries for every code?

After compiling a simple contract, the output are these values: "opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH1 0xF JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP ...
Juan Ignacio Pérez Sacristán's user avatar
4 votes
3 answers
332 views

How do I initialize an array of Structs

I would like to initialize an array of structs: struct person { string firstName; string lastName; } person[3] family = [ person("Will", "Smith"), person("Jada", &...
whamsicore's user avatar
4 votes
0 answers
116 views

Ensuring the atomicity of multiple transactions

I am new to solidity and have been creating single (both basic and complex) transactions. However, I have a question which I couldn't come up with a solution. How can I create 2 (or more) transactions ...
merdoyovski's user avatar
4 votes
0 answers
255 views

how to calculate the message part for pedersen hash in solidity

I am trying to implement pedersen hash using solidity. Is it possible to implement and how to split the message according to the conditions of pedersen hash.
gasbot's user avatar
  • 41
4 votes
5 answers
13k views

How do I inject Web3 into Remix IDE?

when going on to the remix IDE, i get the error No injected Web3 provider found. Make sure your provider (e.g. MetaMask) is active and running (when recently activated you may have to reload the page)....
Taner's user avatar
  • 71
4 votes
0 answers
470 views

Solidity Contract and Library difference

I am learning to program Solidity and just playing around with it in remix. I am creating compiling the following code in Solidity: pragma solidity >=0.4.22 <0.6.0; contract Ballot { ...
Mudabbir's user avatar
4 votes
0 answers
171 views

VM revert on Scalar Multiplication in pre-compiled contracts

I tried to build a wrapper around the precompiled contracts as follows: https://gist.github.com/AlexXiong97/9c24bbd4541323a61fa63100860a5f89 If you paste it into Remix and deploy it, inputting any (...
Alex Xiong's user avatar
4 votes
1 answer
594 views

Order of evaluation: an example

In the Solidity documentation is stated that: The evaluation order of expressions is not specified (more formally, the order in which the children of one node in the expression tree are evaluated ...
Briomkez's user avatar
  • 1,894
4 votes
1 answer
274 views

Estimated gas is always low

web3.eth.estimateGas is always calculating low gas for the transaction. Here is a reference to a trasaction in ropsten. https://ropsten.etherscan.io/tx/...
ToniyaSundaram's user avatar
4 votes
0 answers
3k views

Getting Json file from remix

I have been deploying contracts on rinkeby but we are almost done to go to mainnet. I have been comparing deployments with truffle and remix and there is a huge difference in gas uses, so I would ...
Gustavo Alvarez's user avatar
4 votes
2 answers
2k views

Declaring a memory array of storage pointers in Solidity

I would like to declare a variable as a memory array of pointers to storage arrays of uint256. For example: pragma solidity ^0.4.24; contract A { uint256[] public array0; uint256[] public ...
Jesbus's user avatar
  • 10.5k
4 votes
1 answer
793 views

Does delegatecall pass up the events?

I want to use delegatecall in one function to populate an event from the contract I'm calling. Here's a minimal example: contract Caller { address public callee; function Caller(address ...
Lsaether's user avatar
  • 350
4 votes
2 answers
676 views

Smart Contract firing send ether transaction that's not in the contract

I need some help with my smart contract, here's the smart contract code pragma solidity ^0.4.18; contract UserToken { mapping (bytes32 => uint8) public tokenBalance; bytes32[] public ...
user794468's user avatar
4 votes
0 answers
819 views

Truffle migrate Error Invalid number of arguments to Solidity function

Truffle 4.0.1 I've got a contract declared "is Pausable" (OpenZeppelin framework) and I want to pause it as part of the deployment logic. I'm getting an error, however, when invoking pause() Error: ...
sofend's user avatar
  • 241
4 votes
0 answers
130 views

Autorefill isn't working on Improved Coin code

I've been trying to write a token contract with the autorefill function, but perhaps the code for the token example on the ethereum website is somewhat outdated, because it isn't working. Did anybody ...
novakpoa's user avatar
4 votes
3 answers
3k views

Correctly deploying contracts with web3 1.0 and testrpc (invalid opcode error)

I followed the following tutorial: https://medium.com/@mvmurthy/full-stack-hello-world-voting-ethereum-dapp-tutorial-part-1-40d2d0d807c2 Now this tutorial is not using the recent version of web3 but ...
Etherhacker's user avatar
4 votes
1 answer
2k views

Truffle Bytecode Different from Etherscan Bytecode

I am having difficulty verifying my contract code on Etherscan using the code generated by Truffle. Using Etherscan VerifyContract V1: https://rinkeby.etherscan.io/verifyContract Truffle produced ...
Nyxynyx's user avatar
  • 1,167
4 votes
1 answer
214 views

How to use BTCRelay for my ICO to get funds in BTC?

I want my ICO get investment in BTC also ,When i browse over internet I came up with BTCRelay concept . I tried to read their docs but it make me confused .Anybody give me a simple way to use BTC ...
Satyam Agrawal's user avatar

1
2 3 4 5
107