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
4
votes
2answers
593 views

Throw not generated when accessing mapping with invalid key

I'm trying to implement the current contract: contract Mortal { address owner; event Killed(address indexed from); function Mortal() { owner = msg.sender; } function ...
4
votes
1answer
337 views

Out of gas error deploying library

The following code is compiled with solc 0.3 with correct --libraries linking and deployed to morden. Math library is deployed just fine and can be accessed. However A doesn't get deployed on morden ...
6
votes
1answer
713 views

Can I retrieve the timestamp the contract was mined on, inside of the contract?

I'm aware of the now keyword that aliases block.timestamp (uint): current block timestamp and the time units But I fail on finding a way to get the block timestamp of when the contract was mined. ...
4
votes
2answers
885 views

Does `throw` refund the ether value?

When a contract triggers a throw, the Solidity document states: Solidity will trigger an "invalid jump" and thus cause the EVM to revert all changes made to the state. In this case, what happens ...
9
votes
3answers
2k views

How can I create complex array relationships in solidity?

Hello I'm trying to work out how to create complex relationships in Solidity. In this example a customer will place an order using a function with arguments, however it cannot be for any combination ...
8
votes
1answer
12k views

Where can I learn how to develop DApps using the solidity programming language? [closed]

What resources exist to help people learn the solidity programming language and create smart contracts & DApps on Ethereum?
168
votes
13answers
43k 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 ...
11
votes
3answers
5k views

Internal compiler error: Accessors for mapping with dynamically-sized keys not yet implemented

I have a mapping(string => Person) public map: struct Person { string name; string description; address primaryAddress; string linkToWebsite; string ...
28
votes
2answers
13k views

Can I save structs in a Mapping?

Is it possible to store structs in a Mapping or any dynamic memory structure in my Solidity SmartContract?
6
votes
1answer
2k views

What does 'p.recipient.call.value(p.amount * 1 ether)(transactionBytecode);' do?

Ok, I've seen this at the DAO (Distributed Autonomous Organization) sample tutorial here. And I also looked it up at some other places like the official Solidity documentation here for instance. But I ...
5
votes
1answer
327 views

Contracts as First Class Citizens

I understand a contract being described as a top level abstraction, but what are some architectural and design advantages (and disadvantages) for developers in isolating their design classes into ...
2
votes
0answers
160 views

Using External API in a Contract? [duplicate]

Is it possible (and feasible) to have a solidity contract connect to an external api and execute a contract based on what is found? For example betting on sports games by agreeing to a credible API ...
10
votes
1answer
507 views

What is meant in this tutorial when it says that using throw will "consume all provided gas"?

When reading the solidity documentation (http://solidity.readthedocs.org/en/latest/solidity-by-example.html#voting), I came across this: function giveRightToVote(address voter) { if (msg.sender !=...
5
votes
1answer
301 views

What happens if you chained delegatecalls?

Solidity docs say "only the code of the given address is used, all other aspects (storage, balance, ...) are taken from the current contract." This is useful when creating a library. But what happens ...
28
votes
1answer
14k 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 ...
1
vote
1answer
647 views

How to rebuild solc on Mac OSX?

I need to rebuild solc on OSX. I followed http://solidity.readthedocs.org/en/latest/installing-solidity.html but old version still in place with solc --version. Is there a process to remove existing ...
2
votes
1answer
136 views

What does idx mean or do in this contract?

Here is a contract from https://www.etherchain.org/account/0xc18a451d4ef2a85e7bf8404131c5f994a98bdb15#code What exactly does idx mean or do? function enter() { if (msg.value < 500 finney) ...
5
votes
2answers
2k views

Contracts calling other contracts - setting 'from' field?

I'm aware a very similar question exists - but I feel my use case is sufficiently different to warrant a new question. I have two instances of the following contract Own... contract Own { ...
3
votes
1answer
480 views

Nested vs. flattened functions

Is there any difference if I use nested functions in a contract instead of writing the code two times if the second function is a subset? function doSmth(address user){ transaction1; ...
10
votes
1answer
726 views

Dividing Ether Past Smallest Unit Possible?

I've read that ether is divisible to 1018. Say you're writing a simple contract which takes deposits sent to it divides the deposit in 2 and sends it to 2 separate addresses. What happens if someone ...
6
votes
1answer
962 views

How to convert msg.data to a uint

I am sending ETH to a contract as follows: web3.eth.sendTransaction({from: sender, to: address, value:amount, gas:300000, data:"1234"}); In my fallback function, I can see msg.data has the following ...
7
votes
1answer
412 views

How do I plan for an upgrade on my contract? [duplicate]

Absolute beginner question: If I assume that my contract is complex and will need future features or bugfixes, and that it holds assets and records privileged addresses, how should I prepare for an ...
5
votes
1answer
320 views

How do you access return statements in the Mist UI

If I have a contract and its interface added to Mist and I call a function, how do I access its return statement?
9
votes
2answers
6k views

How does one properly use ecrecover to verify Ethereum signatures?

I've been searching to figure out what I'm doing wrong here, but I've had no luck yet. As far as I can tell, I'm using ecrecover correctly, but I can't seem to get back the signing Ethereum address. ...
11
votes
2answers
10k views

How can I instantiate an array of addresses?

I simply want to create an array with stuff in it. Everything I try is an error message in mist. Even this code snippet I got straight from the docs wont compile: contract C { uint someVariable; ...
14
votes
1answer
8k views

How should we set a import path in solidity?

I failed to compile a solidity file with import statement. Error: Source not found: File not found. import './contract.sol'; How should we set a import path? I used web3.js for compiling. ...
1
vote
0answers
2k views

How can I check if a variable or an array is set or empty or null? [duplicate]

How can I check if a variable or an array is already set, empty or null in solidity? For example, mapping (string => address) addresses; How can we know addresses[key] is set or not?
27
votes
1answer
9k views

Cannot perform write functions in smart contract - invalid address?

I have the following simple smart contract... contract SimpleStorage { uint storedData; function set(uint x) { storedData = x; } function get() constant returns (uint retVal) ...
13
votes
1answer
3k views

How to make external contract function calls from one contract to another?

I'm having a hard time understanding the documentation for making an external function call from one contract to another. In this tutorial there is an example: contract InfoFeed { function info() ...
6
votes
1answer
966 views

Not enough components (4) in value to assign all variables (6)

This is an exception on compilation I am getting with truffle. The code I am running builds a store from a container contract and then makes a call to get a product from it. Store s = Store(saddress)...
5
votes
1answer
831 views

Why does Solidity need modifiers?

Is there any reason for why Solidity has modifiers instead of just having a normal function which is called in the first line of a function body? The docs motivate it with readability but I do not see ...
3
votes
1answer
224 views

How do I reference a certain structure

Here are my declarations and code: struct Key { bytes32 blindedKey; uint deposit; address player; bool revealed; } mapping(address => Key[]) public keys; function seating(bytes32 ...
2
votes
1answer
435 views

Pass an array along when a contract creates a new contract

Can an array be passed along as a contract creates a new contract ? Specifically, an array of addresses. address[] verifiedUsers; new generatePOItokens(verifiedUsers);
4
votes
1answer
932 views

Hash Test: How to produce hash output

Here is a basic hash test. I am trying to reproduce the output with: http://emn178.github.io/online-tools/sha3_256.html Is sha3-256 correct? The output for '1' as the value input is ...
2
votes
1answer
2k views

IF statements in Solidity not behaving as expected

When I fire this function for the first time it seems revealEnd = now; fires because the reveal period ends. Yet revealCount does in fact display '1', indicating that we went into BOTH if statements. ...
8
votes
4answers
3k views

web3.eth.getStorageAt for mapping

How can I get contract mapping storage? Considering this simple contract contract Currency{ mapping(address=>uint) public balances; function deposit(){ balances[tx.origin]++; } } ...
4
votes
2answers
992 views

Can a library function operating on a struct work for non "storage" structs?

I'm just getting started with solidity, and I'm working on a contract that calculates the periodic payment on an amortized loan. My goal is to implement the annuity formula: I've started a library ...
3
votes
1answer
189 views

Odds and Evens: What wrong with the code?

Seems like this should run. I've stripped it down just so that I can enter two player arbitrary choices and have the action end add 1 + 1 and payout to the even player. Neither players get paid ...
5
votes
2answers
674 views

Retrieving historical balance and lifespan of an address

I am coding up a PoC for a free market basic income mechanism, and am trying to figure out how to get the historical balance of msg.sender, as well as the time since that address was generated. ...
8
votes
1answer
1k views

Can a contract access the code of another contract?

Using web3.js, the EVM (bytecode) of a contract can be obtained by web3.eth.getCode(addressOfContract). Can this be performed by a contract using the address of another contract? If so, how? ...
69
votes
2answers
25k 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: ...
7
votes
1answer
603 views

How can I efficiently get a large amount of data from a contract?

I have a contract that will store a lot of data. Offline solutions really don't apply to the problem I'm trying to solve, short of caching (but then I have a cache invalidation problem I'd have to ...
3
votes
1answer
97 views

Is there a comprehensive reference list of all Serpent commands?

Solidity has a particularly nice, comprehensive set of docs, and a flashy GitHub homepage. Is there an equivalent set of documentation for Serpent?
8
votes
3answers
1k views

Is there a comprehensive reference list of all Solidity commands?

Is there a comprehensive reference list of all Solidity commands?
2
votes
0answers
180 views

Blind Auction: Reveal>>>How to successfully fill data fields [duplicate]

http://solidity.readthedocs.org/en/latest/solidity-by-example.html#id2 Not confident in how to "blind" a secret and reveal it. Using http://emn178.github.io/online-tools/keccak_256.html for the hash....
3
votes
1answer
704 views

returning a fixed size 2D array to web3.js

I would like to return a 2D array from solidity code and look at it with web3.js this is the solidity function: uint8 [10][10][100][100] public blocks; function getBlock(uint x, uint y) returns (...
4
votes
1answer
2k views

Enums in Solidity

Enum's are not working in solc? Just tried to compile demo contract from gihub documentation : contract test { enum ActionChoices { GoLeft, GoRight, GoStraight, SitStill }; function test() { ...
4
votes
1answer
8k views

How to install Solidity on Windows?

I've been following the tutorial at https://www.ethereum.org/greeter , but when it gets to the point of installing Solidity, it is apparently no longer maintained on chocolatey so that step doesn't ...
18
votes
3answers
14k views

What is the 'this' keyword in Solidity?

What is the specification of the 'this' keyword in Solidity? How does it work? Sample code from Solidity Features · ethereum/wiki Wiki contract Helper { function getBalance() returns (uint bal) { ...
2
votes
1answer
555 views

How to find unique entries in mappings?

Is it possible to write a function that compares a list of strings or numbers, or both, and determines which items in the list are uniques? could someone provide sample code of how that would be done ...