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,128 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
13 votes
1 answer
938 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{ ...
  • 1,843
6 votes
1 answer
2k views

What is the logic behind token reflections?

I've noticed that a lot of tokens that implement reflections come from safemoon. And I was curious about how safemoon did reflections. I expected to find a for loop somewhere where they are adding to ...
6 votes
0 answers
3k 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 ...
6 votes
1 answer
252 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; }...
  • 63
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?
  • 61
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() ...
  • 1,141
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 ...
  • 7,849
5 votes
0 answers
63 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 ...
5 votes
1 answer
188 views

Is it safe to mark library functions that modify the calling contract's state as public in Solidity?

I am using libraries to reduce the cost of deployment of a contract of which there may be many instances (using a factory contract). When I mark a library function as internal, the code seems to get ...
5 votes
0 answers
364 views

Is there a time oracle for a Solidity calendar library?

According to the solidity documentation: Take care if you perform calendar calculations using these units, because not every year equals 365 days and not even every day has 24 hours because of leap ...
5 votes
0 answers
142 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. ...
5 votes
1 answer
370 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 ...
5 votes
0 answers
74 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"); _; } ... ...
  • 116
5 votes
1 answer
12k views

How does Uniswap calculate price impact without fee on the swap page?

Context: We are creating a smart contract which integrates Uniswap DEX for swapping Tokens to ETH. We need to make sure one swap does not impact the token price more than 3%. We are in need to write a ...
5 votes
0 answers
693 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 ...
  • 151
5 votes
0 answers
985 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; ...
  • 149
5 votes
0 answers
521 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: '../...
5 votes
1 answer
658 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 ...
  • 1,077
5 votes
0 answers
286 views

Interfaces and gas savings

Does it save gas to link to the bytecode of an interface? I tested this is solidity remix and using the interface to link bytecode instead of the full contract, didn't seem to reduce any gas costs for ...
  • 549
5 votes
0 answers
280 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 ...
  • 30.1k
5 votes
2 answers
1k 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 ...
  • 61
5 votes
2 answers
620 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 ...
5 votes
2 answers
3k views

Ethers.js filters events (Only new events)

I have an event set up in the Contract. Contact Packages emit Spend(msg.sender, msg); function sendPackage(msg) external payable returns(bool) { require( msg.value == price, '...
  • 573
4 votes
1 answer
110 views
+150

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 ...
4 votes
0 answers
61 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/...
4 votes
1 answer
266 views

which wallet supports access list(eip-2930)

I am trying to use Access List feature - Link here I am using also ethers.js.. It seems like that ethers.js supports passing access list, but Metamask doesn't yet support this feature. do you know any ...
4 votes
2 answers
149 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", &...
4 votes
0 answers
541 views

How to debug a reverted transaction?

I am writing a smart contract. The smart contract always revert. How can I debug step by step my smart contract? I am coming from javascript, so I was expecting a "console.log" or something ...
4 votes
0 answers
3k views

How do I limit the number of ERC721 NFTs per account?

I would like to restrict the number of NFTs any one address can own. How would you implement this in a Solidity smart contract? Say I have an ERC721 NFT contract, Square.sol: import "../...
4 votes
2 answers
896 views

Uniswap Router deployment error: "UniswapV2Router02" -- Cannot create instance of UniswapV2Router02; no code at address 0xxxxxxxxx

I am trying to fork Uniswap and deploy on Ropsten testnet for educational and testing purposes. From what I gathered, it seems that we need to first deploy the UniswapV2Factory contract, followed by ...
4 votes
0 answers
707 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. * * ...
4 votes
0 answers
733 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 ...
4 votes
0 answers
150 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.
4 votes
0 answers
390 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 ...
4 votes
0 answers
251 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/...
4 votes
2 answers
993 views

Capturing an event fired from a contract that was called from another contract

I'm trying calculate tax on arbitrary items/values. To do this I have a single contract is used as an 'Oracle' to get the tax from an external system. This contract defines functions to be called from ...
  • 41
4 votes
1 answer
519 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 ...
  • 350
4 votes
2 answers
664 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 ...
4 votes
0 answers
805 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: ...
  • 241
4 votes
0 answers
126 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 ...
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 ...
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 ...
  • 1,097
4 votes
1 answer
210 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 ...
4 votes
0 answers
609 views

How to update the Ethereum Wallet Solidity Compiler

I'm using the latest Ethereum Wallet version which is 0.9.0 and I want to update my latest Solidity compiler since it seems that the wallet is using this version 0.4.13+commit.0fb4cb1a.Emscripten....
4 votes
2 answers
1k views

Importing a contract from another contract in NodeJS app

I'm using a function in my NodeJS app to deploy contracts. The user inputs the contract he wishes to deploy and the app deploys it. The structure of the app is . ├── app │   ├── models │   │   └── ...
  • 831
4 votes
0 answers
363 views

Gas cost for bigInt library

I am working on a big integer library in the online compiler. Currently having gas/computational time issues with the modulus function. I first implemented it using repeated subtraction: function ...
user avatar
4 votes
1 answer
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 ...
4 votes
1 answer
777 views

passing byte[] to smart contract using nethereum

I made a solidity function that allow a user to send multiple transactions with the same nonce as a singleton Tx signer: function multipleTransferPreSigned ( bytes[] _signature, address[] ...
4 votes
1 answer
971 views

How do I connect to the Remix JavaScript VM from my front end

I have been developing using Remix and Metamask but it's a slow progress when pushing to the test networks. I have switched to the JS VM in Remix but I am not sure about how to connect my frontend to ...
  • 433
4 votes
1 answer
931 views

Why are getters of public state variables not recognised by interfaces?

In code like the below, address public balance has an automatic getter function (as can be seen in the corresponding ABI). However we need to redefine it to avoid the compiler complaining that Test ...
  • 1,257

1
2 3 4 5
103