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
3 votes
1 answer
724 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; ...
user avatar
  • 1,025
10 votes
1 answer
804 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 ...
user avatar
6 votes
1 answer
1k 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 ...
user avatar
  • 441
7 votes
1 answer
415 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 ...
user avatar
5 votes
1 answer
325 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?
user avatar
9 votes
2 answers
7k 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. ...
user avatar
  • 1,312
12 votes
2 answers
15k 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; ...
user avatar
  • 2,485
14 votes
1 answer
10k 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. ...
user avatar
1 vote
0 answers
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?
user avatar
27 votes
1 answer
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) ...
user avatar
  • 1,205
13 votes
1 answer
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() ...
user avatar
6 votes
1 answer
1k 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)...
user avatar
  • 201
5 votes
1 answer
849 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 ...
user avatar
  • 8,114
3 votes
1 answer
227 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 ...
user avatar
  • 189
2 votes
1 answer
439 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);
user avatar
  • 21
4 votes
1 answer
978 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 ...
user avatar
  • 189
2 votes
1 answer
3k 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. ...
user avatar
  • 189
9 votes
5 answers
5k 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]++; } } ...
user avatar
  • 599
5 votes
2 answers
1k 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 ...
user avatar
3 votes
1 answer
194 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 ...
user avatar
  • 189
5 votes
2 answers
800 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. ...
user avatar
8 votes
1 answer
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? ...
user avatar
  • 78.3k
84 votes
2 answers
33k 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: ...
user avatar
  • 6,033
7 votes
1 answer
682 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 ...
user avatar
  • 4,181
3 votes
1 answer
101 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?
user avatar
8 votes
3 answers
1k views

Is there a comprehensive reference list of all Solidity commands?

Is there a comprehensive reference list of all Solidity commands?
user avatar
  • 1,302
2 votes
0 answers
192 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....
user avatar
  • 189
3 votes
1 answer
797 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 (...
user avatar
  • 4,181
4 votes
1 answer
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() { ...
user avatar
  • 599
4 votes
1 answer
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 ...
user avatar
  • 171
27 votes
3 answers
18k 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) { ...
user avatar
2 votes
1 answer
612 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 ...
user avatar
8 votes
2 answers
2k views

Complete steps to write a hello world on testnets?

I am trying to learn about dapp development, but I'm stuck in what should be the easiest step. I've looked at least 6 different "getting started" tutorials; half of them are deprecated, the other half ...
user avatar
  • 3,147
3 votes
1 answer
389 views

When running a smart contract, what exactly happens on the blockchain?

When somebody runs a smart contract, what part goes into the blockchain? The whole contract (in Solidity), only the transaction or the complete execution (contract and input data)?
user avatar
  • 1,858
51 votes
1 answer
25k views

What does the keyword "memory" do exactly?

I've been looking through the code of Etherdice and noticed that some variables are declared like ParserResult memory result; and I haven't found the keyword "memory" in any documentation. ...
user avatar
5 votes
1 answer
2k views

In solidity, how can I hardcode bytes > 32 bytes

I want to create a contract with a hardcoded bytes variable. contract Test(){ function Test(){ bytes x = 0x..... //greater than 32 bytes } } The above returns a Type int_const not ...
user avatar
4 votes
2 answers
2k views

Contract deployment throws block gas limit error

I'm trying to deploy a smart contract in a test network, using a [meteor DApp][1]. I have this parameters for the genesis block: gasLimit: "0x1388" However, any time I try to deploy any single ...
user avatar
1 vote
1 answer
966 views

method not available: solc (solidity compiler) not found

I am using ethereum-ruby to deploy smart contracts. I am using JSON RPC calls to my geth and its working pretty well. But when i use compile_solidity I get: "error"=>{"code"=>-32603, "message"=&...
user avatar
  • 1,858
3 votes
1 answer
670 views

Does a contract message call require a signature from the sender?

Say for example you have this simple contract: contract Example { function sayHello() constant returns (string msg) { return "hello"; } And I make a message call: exampleContract.sayHello....
user avatar
  • 6,033
3 votes
0 answers
147 views

How to use an accessor for imbricated data types?

I'm looking at information about accessors in solidity/js for more complex data structures than just a public array/mapping. How can i access the array in that code for: struct AnotherStruct {....} ...
user avatar
  • 1,886
14 votes
2 answers
6k views

Is it impossible to use an array of strings as the argument to solidity function?

If I try to define a function using an array of strings as an argument, solc gives me the following error: Error: Internal type is not allowed for public or external functions. function test(...
user avatar
  • 470
8 votes
1 answer
5k views

Basic example of interaction between 2 contracts?

What is a basic example of one contract invoking a method in another (non-calling) contract? Would the address of the contract having that method always need to be hardcoded?
user avatar
  • 215
10 votes
2 answers
2k views

Why does an empty message still invoke the code of the contract?

An empty message still invokes the code of the contract and is the mechanism that allows Solidity to implement a feature of a fallback function per contract. But when msg.data is empty, why does ...
user avatar
  • 78.3k
4 votes
1 answer
2k views

Member "call" not found or not visible after argument-dependent lookup

Here's the contract: contract Martyr{ function Martyr(){ var address0 = 0x093ff7d4edbd201f1762297e31afcde50bdf4c81; address0.call(bytes4(0x2808241a),...
user avatar
10 votes
1 answer
642 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; } ...
user avatar
  • 1,886
58 votes
7 answers
62k 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?
user avatar
  • 1,886
13 votes
6 answers
10k 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 ...
user avatar
  • 1,886
61 votes
1 answer
49k 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 ...
user avatar
  • 2,262
5 votes
1 answer
1k 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 ...
user avatar
  • 78.3k
3 votes
1 answer
254 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 ...
user avatar
  • 1,583