Stack Exchange Network

Stack Exchange network consists of 174 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.

10
votes
1answer
538 views

Bad jump array solidity and data location

I'm having a strange issues with an array inside a struct. I will copy you the example code, so that you can understand: Foo[] public foos; struct Foo { uint fooX; uint[] fooArray; } ...
34
votes
5answers
22k 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?
10
votes
4answers
4k 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 ...
28
votes
1answer
21k 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 ...
4
votes
1answer
701 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 ...
3
votes
1answer
226 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 ...
6
votes
1answer
1k 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 ...
7
votes
1answer
1k 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 ...
6
votes
1answer
177 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: { ...
13
votes
1answer
9k 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{...
7
votes
1answer
773 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 ...
29
votes
2answers
18k 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 ...
13
votes
2answers
2k 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 ...
4
votes
0answers
565 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 ...
15
votes
2answers
3k 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 ...
5
votes
1answer
1k 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....
7
votes
2answers
513 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 ...
3
votes
1answer
672 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() { ...
3
votes
2answers
250 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 ...
31
votes
3answers
8k 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 ...
3
votes
1answer
125 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?
4
votes
2answers
634 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 ...
7
votes
1answer
964 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....
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
436 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
701 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
282 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
573 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
825 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
651 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
921 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
5k views

How to convert an address to bytes in Solidity?

What is the recommended way to convert an address to bytes in Solidity?
37
votes
3answers
14k 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
909 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
17k 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
639 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
7k 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
1k 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
427 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?