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
174 votes
4 answers
46k views

Are there well-solved and simple storage patterns for Solidity?

Simple and appropriate data organization can challenge Solidity newcomers. It wants us to organize everything in ways many of us aren’t accustomed to. Are there well-solved general patterns for ...
Rob Hitchens's user avatar
  • 54.7k
186 votes
13 answers
52k views

Upgradeable smart contracts

If the contract issuer wants to have a way to upgrade the contract code, so that account data and other things carry over, can Ethereum provide this? Also can this be done without changing the ...
Mikko Ohtamaa's user avatar
41 votes
8 answers
15k views

Error while compiling: Stack too deep

When trying to compile, I am getting the following error: "Internal compiler error: Stack too deep, try removing local variables." Is there any way around this? I'm not sure if I'll be able to ...
Amer Ameen's user avatar
15 votes
1 answer
7k views

What fixed or float point math libraries are available in Solidity?

Solidity doesn't have fixed-point, floating-point, or double types. What solutions are there to handle the cases where we really have to represent numbers as percentages or fractions?
Paul Razvan Berg's user avatar
2 votes
1 answer
2k views

Missing Eth after sending to contract

I tried following a tutorial on YT and my ETH has been missing. I keep on looking at the tos and froms but I can't seem to find where my ETH has been sent. This is the created contract address ...
RGJ MIA's user avatar
  • 21
104 votes
2 answers
40k views

What's the difference between 'msg.sender' and 'tx.origin'?

If either are used in the body of a Solidity function that may change the state of a contract (write call), what's the primary difference and/or benefit of using one over the other. For example: ...
dbryson's user avatar
  • 6,363
78 votes
4 answers
65k views

<address>.send vs <address>.transfer best practice usage?

I noticed that address's offer two member functions that perform the transfer of ether to the specified address. send returns false upon failure and transfer raises an exception. In the Solidity ...
Michael's user avatar
  • 1,035
69 votes
7 answers
37k views

How can you decompile a smart contract?

On the blockchain I can inspect the code of a contract, and see the EVM opcodes. Is there a way to decompile this and convert it back to (Solidity) source code?
J-B's user avatar
  • 8,911
45 votes
6 answers
43k views

How can I represent decimal values in Solidity?

I just started writing some solidity and I noticed that there are no decimal values such as double or float. What do you guys do when you need to return send to a wallet let's say 1.57 ether? Or when ...
sfrj's user avatar
  • 772
30 votes
4 answers
35k views

How to get return values when a non view function is called?

I am writing below a simple contract which stores all results of questionnaires for each ID. contract answer{ mapping(address => mapping(string => bool)) voters; struct qList { uint ...
A. Take's user avatar
  • 425
49 votes
12 answers
68k views

How to convert a bytes32 to string

How can I convert a bytes32 to a string? Does anyone has a magic function or library which does it?
arodriguezdonaire's user avatar
40 votes
2 answers
22k views

Deploy contract from contract in Solidity

It's a common pattern to use a hub/factory contract to create multiple instances of a standard contract. It's also common to require a way to enumerate the addresses of the created contracts. Is ...
Rob Hitchens's user avatar
  • 54.7k
104 votes
5 answers
43k views

Difference between require and assert and the difference between revert and throw

I was looking at the docs and I'm looking for clarification on the difference between require and assert and throw and revert. assert(bool condition): abort execution and revert state changes if ...
Daniel Kobe's user avatar
  • 1,581
54 votes
8 answers
31k views

How to quickly test a Solidity function?

There are snippets and functions of Solidity code provided on this Ethereum Stack Exchange and other sites. What are ways to quickly test them, possibly debug a little, and play around?
eth's user avatar
  • 85k
38 votes
2 answers
32k views

How can you call a payable function in another contract with arguments and send funds?

I have a contract named Call: contract Call { ... function () payable { // TODO: Call the call function in the main contract // and forward all funds (msg.value) sent to this contract ...
Pabi's user avatar
  • 1,129
79 votes
2 answers
32k views

Solidity: What is the difference between `view` and `constant`?

Solidity 0.4.16 introduced the view and constant function modifiers. The documentation says: constant for functions: Same as view. Does this mean view is just an alias for constant? If so, why do ...
SCBuergel's user avatar
  • 8,704
34 votes
6 answers
27k views

ecrecover from Geth and web3.eth.sign

I have tried to use ecrecover() to verify the signature of a message. I have looked at lots of references here and elsewhere, like: https://lab-blog.ey.com/2016/12/19/ecrecover/ How does one ...
Daniel Mermelstein's user avatar
66 votes
7 answers
75k views

How to delete an element at a certain index in an array?

Anyone know how to delete an element in a array? Is there any built in method to do that? If not, does anyone know of how to implement such a method?
user697's user avatar
  • 2,166
47 votes
1 answer
31k views

What are Solidity events and how they are related to topics and logs?

I know that indexed arguments index the values for those arguments so that filtering will be faster. But what are topics? And what are they used for? I know that signature of an event is a topic. ...
Narayan Prusty's user avatar
34 votes
1 answer
33k views

What is the receive keyword in solidity?

Solidity has a receive keyword. What is it and how do I use it?
Shane Fontaine's user avatar
19 votes
1 answer
4k views

How much computation can be done in a fallback function?

Simply sending Ether to a contract, will run the contract's code. In Solidity, this code maps to what it calls the fallback function. How much work can be done in a fallback function?
eth's user avatar
  • 85k
77 votes
6 answers
95k views

Fallback function in Solidity

I have seen many examples of the fallback function in Solidity, but I didn't understand any of them. Also, I've seen references to the payable modifier. My questions are: What exactly does the ...
Gopal ojha's user avatar
  • 2,249
58 votes
1 answer
18k views

Are underscores `_` in modifiers code or are they just meant to look cool?

I often see _ in modifiers modifier onlyOwner() { if (msg.sender != owner) throw; _ } Does it execute any code or is it meant to make the code easier to read ?
dor's user avatar
  • 725
54 votes
4 answers
28k views

What is the zero, empty or null value of a struct?

If I have a mapping of string => custom defined struct, how do I check if a value is defined in the mapping? The docs state that "every possible key exists and is mapped to a value whose byte-...
Thomas Clowes's user avatar
94 votes
7 answers
89k views

How to concatenate strings in solidity?

I'm trying to concatenate two strings in solidity. I tried with + or . but neither option works. There is not much documentation on string concatenation yet. Is it even possible? If not, can I ...
q9f's user avatar
  • 32.8k
41 votes
7 answers
26k views

How does a contract find out if another address is a contract?

Is it possible, from within a contract written in Solidity, to check if a contract is placed on a specific address or if this address does not contain any code?
Thorkil Værge's user avatar
35 votes
2 answers
7k views

Ethereum smart contract security checklist

Is there a tool, checklist of methodology to help reviewing smart contract security? E.g. for each of function you review Is there re-entry possibility and how it behaves on re-entry How it behaves ...
Mikko Ohtamaa's user avatar
19 votes
2 answers
5k views

Can a contract access another contract's storage?

I have a contract with numerous complex structs. Is it possible for a second contract to iterate over this data directly? I can't really use public accessor/getter methods as it's not possible to use ...
slothbag's user avatar
  • 433
10 votes
2 answers
2k views

Unable to define greeterContract in the Greeter tutorial. Breaking change in Solidity 0.4.9!

I was following the Greeter tutorial on Go Ethereum wiki and got stuck on the "var greeterContract = web3.eth.contract(greeterCompiled.greeter.info.abiDefinition)" phase returning TypeError: Cannot ...
Henrik's user avatar
  • 103
74 votes
5 answers
27k views

Why does uint8 cost more gas than uint256?

contract A { uint8 a = 0; } costs 20150 + 2000 gas during creation. as compared to contract A { uint a = 0; // or uint256 } costing 5050 + 2000 gas during creation It is odd that a variable ...
uzyn's user avatar
  • 1,100
62 votes
3 answers
38k views

What's the difference between 'address' and 'address payable'?

I saw a Solidity smart contract where some variables were declared with the type address and some were declared with the type address payable. What are the differences between the two? Do they store ...
Jesbus's user avatar
  • 10.3k
36 votes
2 answers
17k views

Ethereum ecrecover signature verification and encryption

The question of signing and verifying signatures with Solidity has been asked in these questions, both of which I have tried to study: How can I sign a piece of data with the private key of an ...
arik's user avatar
  • 503
27 votes
6 answers
16k views

How to compile Solidity contracts with Geth v1.6?

I tried to compile the following contract within geth: pragma solidity ^0.4.8; contract Test { uint256 public value; function Test() { value = 123; } } using the following ...
BokkyPooBah's user avatar
  • 40.2k
23 votes
5 answers
40k views

Conversion of uint to string

I am trying to convert uint to string in solidity. Is it possible to convert? if so how can I convert it? Convertion to base 10 is prefered, but in hexadecimal might also be helpful.
madhan siva's user avatar
13 votes
2 answers
5k views

How to load Solidity source file into geth

Is it possible to load Solidity source file .sol file to go-ethereum. I am using the 'loadScript' method by saving a .js file like the following and loads it. source = "contract test {\n" + " /// ...
niksmac's user avatar
  • 9,663
5 votes
2 answers
10k views

Solidity convert hex string to bytes

I try to convert hex string to bytes. function MyContract() public { string memory str = "A76A95918C39eE40d4a43CFAF19C35050E32E271"; array1 = bytes(str); bytes memory str1 = hex"...
fragnatic's user avatar
4 votes
2 answers
4k views

Remix Warning - No visibility specified, Violate Checks-Effects-Interaction pattern, Function state mutability can be restricted to pure - Can ignore?

Two months ago, I wrote a smart contract with Remix.ethereum.org. Line 1 of my code has: pragma solidity ^0.4.11; It compiled fine with no errors and nor warnings. I tested every function in ...
Curt's user avatar
  • 307
51 votes
7 answers
72k views

How to convert a string to bytes32?

How can I convert a string to a bytes32? Does anyone has a magic function or library which does it? For example, this will works since as input I gave bytes32 . But it does not work with the ...
alper's user avatar
  • 8,368
44 votes
3 answers
15k views

What is the difference between transaction cost and execution cost in remix?

What is the difference between transaction cost and execution cost as seen after contract instantiation in remix? I don't think it matters, but here is my contract: contract DepositCounter { ...
Raine Revere's user avatar
  • 3,590
44 votes
1 answer
23k views

Is it possible to get the transaction hash from within a Solidity function call?

Within a Solidity function, is the transaction hash available as a global variable from within the contract? I would have thought it would be something like tx.hash in the same way you can do tx....
billett's user avatar
  • 1,255
30 votes
4 answers
32k views

Calling function from deployed contract

I want to know how to instantiate an existing contract deployed on the blockchain using its address. e.g: contract A { function f1() {} } A is deployed on the blockchain, and in contract B I ...
Sig Touri's user avatar
  • 1,080
18 votes
1 answer
2k views

Concealing sensitive data in a public contract

I have some sensitive data I'd like to keep in my contract in privacy. I'd like to make a simple version of Zero-Knowledge Proofs and have an idea in mind. Let's say I have a customer who filled out ...
Igor Barinov's user avatar
  • 2,128
18 votes
4 answers
8k views

How can I call a constant function without spending any gas inside a transaction function?

I have a sorted linked list that contains around 1000 items. When I receive a new item my goal is to push the item to the list keeping the sorted order. So if I receive very small value, I am required ...
alper's user avatar
  • 8,368
75 votes
7 answers
119k views

How do you get a json file (ABI) from a known contract address?

I want to watch a Solidity contract using the Mist browser. I know how to do that and it needs the address and the json. I have the address, but I don't have the json. I do have the source code. Can ...
Thomas Jay Rush's user avatar
50 votes
3 answers
18k views

Where do contract event logs get stored in the Ethereum architecture?

Background on Events: https://github.com/ethereum/wiki/wiki/Solidity-Features Events allow the convenient usage of the EVM logging facilities. Events are inheritable members of contracts. When they ...
Alan Wunsche's user avatar
  • 1,655
29 votes
2 answers
5k views

What is the merit of creating new smart contract languages like Solidity instead of using other languages?

What is the pros and cons of creating new languages like Solidity for smart contracts instead of using other computer languages like Golang or Python?
Satoshi Nakanishi's user avatar
20 votes
2 answers
9k views

Is transfer() still safe after the Istanbul update?

In other words, is using transfer() safe? function transfer(address contractB) public { contractB.transfer(1000); //balances[msg.sender] -= 1000; } How about using call.gas? function ...
Robert Ggg's user avatar
16 votes
9 answers
26k views

How to Fix "Stack Too Deep" Error?

I know that this has been covered in other questions here but I'm not sure what's happening in my case. My code is returning a compiler error "Stack too deep, try removing local variables." But I only ...
Jeffrey Liang's user avatar
14 votes
5 answers
6k views

How to Compile and Deploy a Smart Contract without running a full node?

I'm new to solidity and smart contract programming. I have already made and deploy smart contracts successfully, but always using Mist. Now I'm not able to do so, because I can't complete a node ...
Moisés Briseño Estrello's user avatar
9 votes
1 answer
2k views

Does Solidity's constant keyword do anything?

It seems that the purpose of function foo() constant {} is to indicate that a function does not change the contract's state. And yet, as it states here, the compiler doesn't actually enforce this. So ...
redsquirrel's user avatar

1
2 3 4 5
32