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
5
votes
1answer
363 views

Catch on throw from contract

Is there any built-in way of catching throw clauses? For example, if I'm building a voting application where people must be given permission by the chairperson before voting, otherwise the contract ...
7
votes
1answer
2k views

Checking zero value of structure

I have the following statements: Voter sender = voters[msg.sender]; if (!sender || sender.voted) throw; I'm new to solidity, so I might not be aware of how (or if) coercion works. As I found out in ...
9
votes
2answers
2k views

Check if Contract variable is undefined

How can I check if an Contract variable is undefined in Solidity?
10
votes
3answers
11k views

Visual Studio Code Ethereum tutorial

Are there any tutorials on how to use MS Visual Studio Code to write contracts in solidity?
3
votes
1answer
296 views

What is the best way to represent infinity in Solidity?

Solidity does not natively support infinity, so how would I represent infinity as a variable in Solidity? For example, if I wanted to write an implementation of Dijkstra's algorithm in Solidity it ...
5
votes
1answer
2k views

How to install solidity in Visual Studio?

I see microsoft visual studio now supports solidity and smart contracts deployments. The release notes state: Creates project scaffolding with smart contract samples Supports context sensitive menus ...
-1
votes
1answer
148 views

Interface order of functions [closed]

I am creating a contract with the function 1() function 2() function 3() in a reasonable order. This order is in the "interface" created by the ethereum wallet or solidity browser (for me) ...
4
votes
2answers
548 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
333 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
705 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
872 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?
164
votes
13answers
38k 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
12k 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
315 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
159 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
486 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
277 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
13k 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
641 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
121 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
409 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
689 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
911 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
411 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
9k 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
7k 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
951 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
805 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
918 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
923 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
186 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
595 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? ...
66
votes
2answers
22k 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
579 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
96 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?