Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

8
votes
1answer
3k views

How do I access member variables of a contract from web3.eth?

For example: enum Stages { AcceptingBookings, StopAcceptingBookings, Finished } Stages public stage = Stages.AcceptingBookings; function rand ( uint256 param) atStage(Stages....
9
votes
3answers
2k views

What's the fastest way to mine a transaction so I can test contracts quickly?

I am developing a solidity automated test framework in nodejs that uses events/logging extensively. The use of events eliminates (I believe) all the RPC simulators out there. It's also frustrating ...
2
votes
1answer
453 views

Subcurrency Example: Why always be the “minter” using browser compiler?

A note in the docs referring to the contract example SubCurrency states: This is not a nice example for browser-solidity. If you use browser-solidity to try this example, you cannot change the ...
13
votes
3answers
1k views

What design patterns are appropriate for data structure modification within Ethereum smart contracts?

I am looking to hear about design patterns that people have implemented within Ethereum smart contracts to allow for post deploy modification of data structures. For example, say I have a contract ...
7
votes
2answers
704 views

Can I compile a smart contract without removing the line breaks?

According to an official document, compiling a smart contract needs to remove all the line-breaks in the contract's source-code: If you have the SolC Solidity Compiler installed, you need now ...
9
votes
2answers
5k views

How to concatenate a bytes32[] array to a string?

I am passing an array of bytes32 to my function. This array can contain numbers or hashes etc. to identify an object. In a new use case I want to pass a URL to this function by splitting the URL into ...
5
votes
0answers
303 views

Is there a SetTimeout function in Solidity? [duplicate]

Essentially, is there a SetTimeout in Solidity? creationTime = now; lastBlockNumberA = block.number - 1; first = lastBlockNumberA; if(now >= creationTime + 1 days){ lastBlockNumberB = block....
14
votes
3answers
2k views

Accessing past values of Smart Contract variables

I would like to know if is possible to inquiry variable values using older blocks. For example I have contract Simple { string32 message public; function Simple() { message = msg....
3
votes
0answers
628 views

Checking for empty mapping element [duplicate]

What is the best way to know if an element is " empyt " inside a mapping ? For example mapping ( address => uint) balances; If the user already used the contract there will be an address => "...
5
votes
3answers
2k views

How to compare msg.data (calldata) data type to an integer data type uint256?

As per my question here: I need to compare msg.data (specifically, numbers that are sent with the sendTransaction data object) to a data type of uint256 within my contract. How is this possible?
5
votes
1answer
1k views

Exception in Contract Reverts Entire Stack, Uses all Gas

I added a check to make sure when I send ether that if it fails, I attempt to abort the transaction using a throw. Per example here: Solidity Exceptions When make a call to a function that does ...
4
votes
1answer
831 views

If statement doesn't hit certain conditions

I'm currently working on a very simple(first project) market in solidity and i'm having an issue with a piece of code : contract smallMarket{ struct transaction { uint timeStamp; ...
9
votes
2answers
1k views

How to pass struct mappings to solidity functions?

I have two mappings (uint => customStruct) called listA and listB. I want to run both through a single function to perform operations on the contents. How do I pass this type into a function so ...
2
votes
1answer
665 views

Uncaught Error: could not decode, json: cannot unmarshal array into Go value of type string(…)

I'm trying to use my already deployed contract using web3.js from my console but i'm having issues. I get my compiled contract from browser-solidity then do: var web3 = new Web3(new Web3.providers....
13
votes
1answer
930 views

Struct not being stored in mapping when it contains more than two 'string' properties. Bug?

I am playing around with Solidity, and have encountered an extremely bemusing issue. I want to have a mapping of Address instances (postal addresses NOT the address type) Address is a custom defined ...
9
votes
5answers
6k views

How to convert an address to bytes in Solidity?

What is the recommended way to convert an address to bytes in Solidity?
38
votes
3answers
15k 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-...
11
votes
2answers
937 views

How to build an AST for Solidity?

I'm trying to build a parser for Solidity, and it would help if I could build a working version off of the existing parser. I've tried looking at the source code on the official git, but I haven't ...
9
votes
2answers
331 views

Why do I get serialization errors in calling events?

I have put some events in my contracts like this event TokenTransfer(address indexed sender,address indexed receiver,uint32 indexed num_tokens); event ExceptionEvent(uint16 indexed retcode,address ...
2
votes
2answers
2k views

Attaching an address for a contract to call another contract

I am writing code where I want to call other contracts within my current contract. Bank.sol contract Bank { address owner; mapping (address => uint) balances; function init() ...
27
votes
5answers
18k 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 ...
4
votes
2answers
644 views

Why isn't my contract getting a msg.sender? (solc 0.2.0-1)

TL;DR: Second's msg.sender isn't being set when it should. Consider these two contracts: First.sol: import "Second.sol"; contract First { address public second; function First() { } ...
19
votes
1answer
8k views

How can I verify a cryptographic signature that was produced by an Ethereum address key pair

If I have a cryptographic signature from an Ethereum address key pair, how can I verify that signature?
21
votes
1answer
2k views

How does the solidity optimizer work?

The compiler for solidity supports the flag --optimize which performs some set of optimizations to the compiled solidity code, typically resulting in a reduction of gas costs. How does the optimizer ...
11
votes
2answers
5k views

What does a “bad JUMPDEST” error mean?

When I send a transaction to call my contract, it's causing a bad JUMPDEST error. The Ethereum wiki says this error is caused when a JUMP instruction jumps to a location that wasn't marked as a jump ...
8
votes
1answer
429 views

How to handle library function prototype changes?

One great thing about using a library is that the library code can be modified, and as long as the api function prototype stays the same, all we need to do is point to the new address of the updated ...
16
votes
2answers
13k views

How can I return multiple strings from a contract function?

In solidity it's obvious how to get a single string returned from a function. But, I'd like to have the smart contract return multiple string values. Is there a way to do this?
23
votes
2answers
8k views

'internal' keyword in a function definition in Solidity

Does the internal keyword in a function definition such as: function doSomeThing(uint _param) internal {...} work similar to designating a method as private in other languages and thus makes the ...
3
votes
1answer
770 views

Getting a solc error: uint176 - Identifier not found or not unique

I'm working on an "Infosphere" contract, an arbitrary key/value store any individual or contract can use. You can take a look at it here: https://github.com/SafeMarket/dapp/blob/...
11
votes
1answer
5k views

How to write my first Solidity “Hello World” smart contract?

I have never written a smart contract before because there is a lot attached to it getting it working. But I finally want to learn it now. I want to write a simple mininmal working smart contract ...
17
votes
2answers
5k views

Why aren't Solidity sha3 hashes not matching what other sha3 libraries produce?

Solidity has a function named sha3 and I tested it with an empty string input. It is not matching what other sha3 libraries produce. I see contracts written by others using the same sha3 function ...
9
votes
1answer
681 views

How to avoid/detect multiple internal transaction out-of-gas side effects?

Following an issue I opened in github, this bothers me. The operation described in the issue, which happened during following avsa's tutorial on creating a DAO, generated two internals transactions as ...
8
votes
1answer
532 views

Why are contracts limited to only the previous 256 block hashes?

Why are contracts limited to only the previous 256 block hashes using the BLOCKHASH opcode (and corresponding functions in Solidity and Serpent)? Why does another contract, such as this, need to be ...
5
votes
1answer
303 views

Is there available source code for the Ethereum parser (JS/Solidity or Python/Serpent?

I've tried looking at the source code, but I'm unfamiliar with the structure. I can't seem to find a parser module or source code. I'm attempting to understand the parser and perhaps write one from ...
24
votes
6answers
4k views

What are common pitfalls or limitations when coding in Solidity?

What would be on your list to warn other developers about? What works in most other languages that does not work, or behave as expected, in Solidity? For example only: what parameters can be passed ...
12
votes
1answer
1k views

How was Solidity conceived and what design tradeoffs were made when building it?

Solidity is a new language designed specially for writing Ethereum smart-contracts. As compared with Serpent, which is an extension to Python semantics, Solidity is completely new and borrows ...
45
votes
7answers
6k views

How can I verify that a contract on the blockchain matches the source code?

Given the (Solidity) source code of a smart contract, is there a way to deterministically compile the code and compare it with the code on the blockchain? I want to verify that the contract does what ...
47
votes
4answers
12k 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?
20
votes
3answers
4k views

Fundamental limitations between Solidity and Serpent

Solidity can be considered a "higher level" language than Serpent. Are there any "low level" features in Serpent or that could be implemented in Serpent, that are either impossible or infeasible to do ...
7
votes
1answer
423 views

What's the limitation that requires Solidity array dimensions to be declared backwards?

From docs: In Solidity, array dimensions are declared backwards from the way you might be used to declaring them in C or Java, but they are access as in C or Java. For example, int8[][5] ...