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
38
votes
1answer
17k 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. What I ...
5
votes
1answer
1k 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 ...
4
votes
2answers
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 ...
1
vote
1answer
747 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"=&...
3
votes
1answer
527 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....
3
votes
0answers
133 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 {....} ...
13
votes
2answers
4k 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(...
8
votes
1answer
4k 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?
6
votes
2answers
861 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 ...
4
votes
1answer
1k 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),...
10
votes
1answer
556 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; } ...
41
votes
5answers
32k 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?
12
votes
5answers
5k 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 ...
42
votes
1answer
30k 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
816 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
243 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
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 ...
7
votes
1answer
2k 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
187 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: { ...
16
votes
1answer
12k 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{...
9
votes
1answer
1k 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 ...
34
votes
2answers
22k 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 ...
15
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
692 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 ...
16
votes
3answers
6k 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
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....
7
votes
2answers
555 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
700 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
289 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 ...
39
votes
3answers
10k 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
131 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
829 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
1k 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....
10
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
576 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 ...
15
votes
4answers
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 ...
7
votes
2answers
791 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
6k 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 ...
6
votes
0answers
494 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....
16
votes
3answers
3k 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
919 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
932 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
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 ...
2
votes
1answer
851 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....
15
votes
1answer
993 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 ...
12
votes
6answers
8k views

How to convert an address to bytes in Solidity?

What is the recommended way to convert an address to bytes in Solidity?
42
votes
4answers
18k 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-...