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.

4,922 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
13 votes
1 answer
922 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{ ...
user avatar
  • 1,813
10 votes
2 answers
861 views

Error: "message":"function \"Ballot\" arguments must include \"proposalNames\""}

I am trying below code to write Voting Contract referring to Solidity documentation pdf. Code compiles without error but I am getting below error while deploying. writing Ballot to app\meta\Ballot\...
user avatar
  • 149
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 ...
user avatar
6 votes
1 answer
222 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; }...
user avatar
  • 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?
user avatar
  • 61
5 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 ...
user avatar
5 votes
1 answer
150 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 ...
user avatar
5 votes
0 answers
304 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 ...
user avatar
5 votes
0 answers
124 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. ...
user avatar
5 votes
1 answer
337 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 ...
user avatar
5 votes
0 answers
66 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"); _; } ... ...
user avatar
  • 116
5 votes
0 answers
11k 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 ...
user avatar
5 votes
0 answers
892 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; ...
user avatar
  • 149
5 votes
0 answers
486 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: '../...
user avatar
5 votes
1 answer
649 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 ...
user avatar
  • 1,057
5 votes
0 answers
278 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 ...
user avatar
  • 29.1k
5 votes
1 answer
1k views

Call write function, which doesn't change contract value

I'm new in smart contracts and faced with one problem. After deploying contract to my test local blockchain network, i try to set new value via setter, after that I call get method of contract and it ...
user avatar
  • 61
5 votes
2 answers
610 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 ...
user avatar
5 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() ...
user avatar
  • 1,131
5 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 ...
user avatar
  • 7,699
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, '...
user avatar
  • 563
4 votes
1 answer
215 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 ...
user avatar
4 votes
2 answers
91 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", &...
user avatar
4 votes
0 answers
438 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 ...
user avatar
4 votes
2 answers
780 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 ...
user avatar
4 votes
0 answers
586 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. * * ...
user avatar
4 votes
0 answers
643 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 ...
user avatar
4 votes
0 answers
120 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.
user avatar
4 votes
0 answers
239 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/...
user avatar
4 votes
1 answer
2k views

How to unsubscribe logs / events?

There are two ways to subscribe/watch to logs/events: Subscribe: var subscription = web3.eth.subscribe('logs', { address: '0x123456..', topics: ['0x12345...'] }, function(error, result){ ...
user avatar
4 votes
2 answers
935 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 ...
user avatar
  • 41
4 votes
1 answer
422 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 ...
user avatar
  • 350
4 votes
2 answers
660 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 ...
user avatar
4 votes
0 answers
256 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 ...
user avatar
  • 509
4 votes
1 answer
1k views

Solidity link to external library address - use Lib for uint256 breaks

I'm trying to link my contract to an external library by defining an interface contract that defines the library functions and the main contract that refers to the actual library address. My library ...
user avatar
4 votes
0 answers
796 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: ...
user avatar
  • 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 ...
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 ...
user avatar
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 ...
user avatar
4 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 ...
user avatar
  • 51
4 votes
0 answers
608 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....
user avatar
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 │   │   └── ...
user avatar
  • 821
4 votes
0 answers
354 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 ...
user avatar
4 votes
1 answer
917 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 ...
user avatar
  • 423
4 votes
1 answer
847 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 ...
user avatar
  • 1,257
3 votes
0 answers
35 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/...
user avatar
3 votes
0 answers
421 views

Creating an Automatic NFT trader

(Apologies for keeping the questions so broad but not sure of the starting point at this stage) Hi All, I am trying to build an automatic NFT trader where a smart contract will buy the NFT from ...
user avatar
3 votes
0 answers
222 views

How to calculate sine and cosine in Solidity?

How can I calculate sine and cosine? Is there any library?
user avatar
3 votes
0 answers
110 views

Include library function without function body

Using solc 0.5.0 it's possible to compile a contract that has a library function implemented with no body. For example: library Hasher { function MiMCSponge(uint256 in_xL, uint256 in_xR) external ...
user avatar

1
2 3 4 5
99