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.

3,322 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
13
votes
1answer
873 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{ ...
9
votes
2answers
700 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\...
6
votes
0answers
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
1answer
121 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; }...
6
votes
4answers
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?
5
votes
0answers
99 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
0answers
95 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
1answer
219 views

Re-entrancy attack explanation and possible fix for specific NFT token - hashmasks

One popular recent NFT project - Hashmasks - Tweeted that some coder called 'samczsun' uncovered a possible re-entrancy attack in their mint function which would have allowed to mint more than the ...
5
votes
0answers
235 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
0answers
37 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"); _; } ... ...
5
votes
0answers
9k 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
1answer
2k views

Reset all values in a mapping

I am trying to figure out how to have the balance of all players reset to (amount) when a certain condition happens. This is the function that will update a specific player balance. How do I make it ...
5
votes
1answer
564 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 ...
5
votes
0answers
239 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 ...
5
votes
1answer
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 ...
5
votes
2answers
528 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
1answer
798 views

How to send an ETH address from a webpage to a smart contract?

What's the best way to get an ETH address from a website form submission (php) passed to a smart contract in order that the smart contract can send some new minted Tokens to the ETH address collected ...
5
votes
2answers
1k 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() ...
5
votes
1answer
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 ...
4
votes
0answers
28 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
0answers
209 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 `*...
4
votes
0answers
40 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
0answers
474 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; ...
4
votes
0answers
421 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: '../...
4
votes
0answers
206 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
1answer
1k 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){ ...
4
votes
2answers
698 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 ...
4
votes
1answer
249 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 ...
4
votes
2answers
605 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
0answers
164 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 ...
4
votes
1answer
785 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 ...
4
votes
0answers
747 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: ...
4
votes
0answers
122 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
3answers
2k 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
1answer
208 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
2answers
973 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 ...
4
votes
0answers
600 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
2answers
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 │   │   └── ...
4
votes
0answers
324 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 ...
4
votes
1answer
977 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 ...
3
votes
0answers
224 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 ...
3
votes
0answers
48 views

Uniswap path generation

The uniswap contract has a function called swapTokensForExactTokens. One of the arguments to this function is an array of addresses called "path" which is the route that the transfer will ...
3
votes
0answers
45 views

How does the EVM achieve smart contract storage allocation and isolation?

How does the EVM achieve smart contract storage allocation and also be able to isolate each contract's storage so that it's not externally accessible by other contracts? From a Solidity developer's ...
3
votes
0answers
47 views

Did Solidity ever release a new feature in a version that was rolled back in later versions?

The question title is pretty self-explanatory. I'm wondering if that ever happened. And if so, what were those features and which were the Solidity versions where they were released/rolled back?
3
votes
2answers
74 views

Link a library to a smart contract only with Solidity and bytecode

I work in Truffle development environment and use Windows PowerShell. My Solidity code is a test code and is simple. There is a library called Alireza that just compares two uint values. There is a ...
3
votes
0answers
18 views

Difference in calldata and arguments

This may be a dumb question, but I'm trying to understand is there a difference re: byte-wise or gas-wise in between using calldata and explicitly mentioning arguments. For example, for this struct: ...
3
votes
1answer
353 views

How to pass a blank bytes calldata into a solidity function call?

I have a function that looks like this: function foo(uint _someVar, bytes calldata _data) public { ... } Then I make a call to it from another function with "" as _data: foo(123, "&...
3
votes
1answer
82 views

how do I know that NFT is from the right person

I understand the NFT (at least solidity part).. There's something that's bugging me though. Let's say someone made a super great cat(cat1), published it to ipfs, then called the ERC721 contract and ...
3
votes
2answers
417 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 ...
3
votes
0answers
385 views

Safe implementation on Solidity 0.8.0 of a withdrawal and a refund

I'm here for asking of a SECURE way to implement on solidity 0.8.0 two functions: 1-Withdrawal() which sends all the ether of the smart contract to the owner address. My current implementation is: //...

1
2 3 4 5
67