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
15 votes
6 answers
14k views

Sorting an Array of integer with Ethereum

I'm trying to have a simple array of integer sorted in Solidity but i couldn't find any real ressources so instead i'm trying to do it "the hard way" but so far with very little success. Is anyone ...
user697's user avatar
  • 2,156
76 votes
1 answer
61k views

How to Initialize a Struct?

I have a struct like so : struct fooStruct { uint foo; uint figther; } I would like to initialize that struct but it won't be stored in a mapping but inside an array. Is there a way to ...
jayD's user avatar
  • 2,462
6 votes
1 answer
2k views

How does a Solidity fallback function work with the raw CALL opcode of the EVM?

Since a fallback function is a Solidity feature, how does it work if the EVM opcode CALL is used? If msg.data is empty, how can Solidity run the fallback function? Shouldn't the EVM just transfer ...
eth's user avatar
  • 85k
3 votes
1 answer
261 views

How problematic is transitioning Augur's full-Serpent smart contract suite?

I read here that Augur's smart contract suite is actually written in Serpent. I'm aware that it is a relatively well supported language at the moment (at least compared to Mutan and LLL), but given ...
Joël's user avatar
  • 1,710
8 votes
1 answer
2k views

How does a fallback function rejecting ether work?

A contract in Solidity can have a fallback function like: // This contract rejects any Ether sent to it. It is good // practise to include such a function for every contract // in order not to loose ...
eth's user avatar
  • 85k
11 votes
1 answer
3k views

Who pays gas when a contract function that creates/calls another contract is called?

If I call a function of Contract1, that creates/calls another Contract2. Who pays the gas used to call Contract2 ? I think it's Contract1 - the second msg.sender. In that case, how can I make the ...
Hcharlanes's user avatar
  • 1,135
6 votes
1 answer
241 views

Why do some functions from my contract end up in the ABI while others don't?

Using the greeter example, The original contracts is written with 4 methods: mortal(), kill(), greeter(), and greet(). Why then when I look at the mined contract does it show me an ABI of: { ...
ZMitton's user avatar
  • 2,730
24 votes
1 answer
29k views

Mapping with array as Key Or Value data type

Is it possible to do a mapping with an Array as key/value ? Where an array would exist for each value ? I'm actually looking to store structs in a mapping but can't seem to have it work. Struct Foo{...
jayD's user avatar
  • 2,462
10 votes
1 answer
3k views

What happens if you call a non-existent function of another contract that has no fallback function in Solidity?

Let's say you call a function at another contract in Solidity: contractB.doFunction() It would then match it using the function signature to run the function in contractB. If there's not match, it ...
Simon de la Rouviere's user avatar
44 votes
2 answers
31k views

Solidity, create contract from contract

Based on documentation it should be possible to create new contract from contract contractAddress = new OwnedToken(name); When I invoke this method from contract, the address I receive seems to be ...
Ales's user avatar
  • 915
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
4 votes
0 answers
737 views

Why are underscores used in front of parameters, instead of contract member variables? [duplicate]

In Solidity, for example, why: function Greeter(string _greeting) public { greeting = _greeting; } instead of: function Greeter(string greeting) public { _greeting = greeting; } The latter ...
eth's user avatar
  • 85k
24 votes
3 answers
13k views

What is the purpose of underscores in front of parameters?

I see contracts that use underscores in front of parameter names, like so: function Greeter(string _greeting) public { greeting = _greeting; } What's the purpose of these underscores? Do they ...
Joël's user avatar
  • 1,710
5 votes
1 answer
2k views

Increment a global variable - can EVM nodes overwrite each other?

I have the following contract: contract Contract{ address minter; uint gid; //... //constructor function Contract(){ minter=msg.sender; gid=0; } function kill(){ if (msg....
Eamorr's user avatar
  • 441
7 votes
2 answers
713 views

Is it possible to invalidate a smart contract?

How can I invalidate a smart contract that has already been deployed? I might want to do so because of business reasons, and maybe beneficial network effects. Is it possible to invalidate a smart ...
niksmac's user avatar
  • 9,663
3 votes
1 answer
792 views

How can I use msg.value twice?

I try to deploy the following code: contract Sample { struct Participant { address etherAddress; uint amount; } Participant[] public participants; uint public amountRaised; function() { ...
Maxim Ananko's user avatar
3 votes
2 answers
465 views

From the solidity SubCurrency example: return statements

Obviously this is rookie question, however I do not believe Solidity docs, nor W3Schools explicitly state this. In the return statement, is the second line in the block equivalent to a second Then ...
Zach_is_my_name'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
3 votes
1 answer
139 views

How can the global registrar be called from a contract?

I want to call what i would do in geth with registrar.owner(namevar) from a solidity contract. Is this possible - and how?
Joe's user avatar
  • 41
5 votes
2 answers
2k views

Is it safe and effective to use 128 bit integers to track wei in a contract in order to save gas?

The default type for Wei in Solidity is the 256 bit unsigned integer. (e.g. msg.value) However, to track 1.7e38 wei (1.7e20 ether) you only need a 127 bit integer. That's a gigantic number not ...
Paul S's user avatar
  • 4,271
7 votes
1 answer
2k views

What is the best way to send multiple transactions without running out of gas for seeding?

I'm having an issue where sending a single transaction work but sending multiple doesn't. I'm attempting to Seed my contract with data using using web3.js and it works fine. mycontractinstance....
jayD's user avatar
  • 2,462
9 votes
1 answer
4k 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....
user2890278's user avatar
11 votes
3 answers
3k 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 ...
Paul S's user avatar
  • 4,271
2 votes
1 answer
720 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 ...
Zach_is_my_name's user avatar
16 votes
4 answers
2k 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 ...
Thomas Clowes's user avatar
7 votes
2 answers
964 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 ...
q9f's user avatar
  • 32.8k
9 votes
2 answers
8k 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 ...
Stefan's user avatar
  • 181
6 votes
0 answers
1k 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....
user2890278's user avatar
19 votes
3 answers
5k 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....
croll83's user avatar
  • 193
3 votes
0 answers
1k 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 => "...
beginerether's user avatar
7 votes
3 answers
3k 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?
user2890278's user avatar
5 votes
1 answer
2k 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 ...
Paul S's user avatar
  • 4,271
4 votes
1 answer
1k 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; ...
beginerether's user avatar
9 votes
2 answers
2k 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 ...
slothbag's user avatar
  • 433
2 votes
1 answer
1k 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....
jayD's user avatar
  • 2,462
15 votes
1 answer
1k 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 ...
Thomas Clowes's user avatar
21 votes
6 answers
25k views

How to convert an address to bytes in Solidity?

What is the recommended way to convert an address to bytes in Solidity?
eth's user avatar
  • 85k
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
14 votes
5 answers
5k 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 ...
hrishioa's user avatar
  • 479
9 votes
2 answers
385 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 ...
codestruggle's user avatar
2 votes
2 answers
3k 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() ...
codestruggle'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
4 votes
2 answers
760 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() { } ...
Tim Coulter's user avatar
  • 1,049
30 votes
1 answer
14k 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?
Piper Merriam's user avatar
33 votes
1 answer
5k 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 ...
Piper Merriam's user avatar
13 votes
2 answers
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 ...
Niran Babalola's user avatar
8 votes
1 answer
772 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 ...
shiso's user avatar
  • 1,036
29 votes
2 answers
40k 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?
Ethan Wilding's user avatar
36 votes
3 answers
26k 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 ...
Terek Judi's user avatar
3 votes
1 answer
893 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/...
Akhil F's user avatar
  • 1,898