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
9
votes
1answer
1k views

Check if msg.value is even?

I'm trying to check whether the amount send by an account is even. For now, I have the code below but when I send only 1 ETH, it doesn't not come back. Seems odd (pun intended :p ) uint amount; ...
48
votes
3answers
31k views

How do you refer to a contract own address inside it?

I am attempting to use 2 contracts together, and I need my 2nd contract to pass his own address to the first contract. Is there an easy way to do this? Like this.address? Or should I update my ...
1
vote
3answers
1k views

Syntax highlighting for Solidity VS Code extension not working on linux

Even if the extension installation completes correctly, syntax highlighting does not work.
10
votes
1answer
8k views

Is it possible to have mappings inside mappings?

Is this possible? mapping(address => mapping(uint => customStruct[])) someName Because I cannot debug and find my mistake... is there not enough gas, or it crashes on this code, while trying ...
7
votes
2answers
2k views

What is the purpose of tokenRecipient contract in token example?

The example of how to create a token (https://www.ethereum.org/token) includes contract tokenRecipient. Why is it there?
4
votes
2answers
4k views

How to create a data structure in Solidity with no limits on size?

In solidity we are not allowed recursive Structs, so I cannot create a recursive data structure with unlimited nodes. Similarly, Solidity Arrays are fixed to the size you initialize them with. So I ...
7
votes
4answers
741 views

Splice Struct Entry by Index in Solidity

I have a struct and I'd like to remove an item by index: struct Payout { address addr; uint yield; } Payout[] public payouts; I'm not familiar with structs and more use to dealing with arrays ...
35
votes
1answer
11k views

Is it possible to get the transaction hash from within a Solidity function call?

Within a Solidity function, is the transaction hash available as a global variable from within the contract? I would have thought it would be something like tx.hash in the same way you can do tx....
9
votes
2answers
4k views

How to implement events in solidity

I have an error whenever I add the event line for EVM logging and to notify anyone listening that this transfer took place. function sendCoin(address receiver, uint amount) returns (bool sufficient) {...
7
votes
3answers
3k views

How to import solidity libraries in mix?

Working in the MIX environment, I'd like to try using a libraries and contracts defined in different files. However, the main contract always gets an error from MIX, no matter how I define the "...
4
votes
1answer
460 views

How can I split certain part of a number variable?

In a smart contract using Solidity, how can I split certain characters of a number variable? I specifically need to take last two symbols of a hexadecimal number.
11
votes
1answer
612 views

Constructor not working properly

After I mine the following contract giving the array [true, true, true] as _bools I would expect [true, true, true] to be returned by getBools(). Instead [false, true, true] is returned. Is there ...
25
votes
3answers
10k views

How does Solidity's sha3 / keccak256 hash uints?

This is not a question about the issue with Ethereum using a non-standard sha3. I have found the right JS hashing library, and am able to get matching hashes in JS and Solidity on byte strings. What I ...
8
votes
1answer
5k views

How to pass arbitrary bytes to a function (2016)

I'm trying to implement a contract which will store bytes blob, a dynamic bytes array. For example I have following struct: Sign { address signer; bytes16 signType; bytes sign; } plus ...
13
votes
2answers
5k views

How to load Solidity source file into geth

Is it possible to load Solidity source file .sol file to go-ethereum. I am using the 'loadScript' method by saving a .js file like the following and loads it. source = "contract test {\n" + " /// ...
25
votes
3answers
13k views

Store data in mapping vs. array

I see there're some Solidity examples that are using mapping for storing state, and some are using arrays. For example this example is using mapping: struct Campaign { .... } uint numCampaigns; ...
7
votes
1answer
2k views

Constructor auto generation and property visibility

Suppose I have the folloing: contract Owned { address owner; function owned() { owner = msg.sender; } modifier onlyOwner() { if (msg.sender == owner) _ } } ...
9
votes
1answer
623 views

Is it convenient to use mappings as temporary KeyValue instances?

Consider the following contract that illustrates the problem. Here we have a dynamic array of mappings, add() is meant to add a fresh new mapping to the end of the array, return the value for mapping ...
9
votes
2answers
4k views

constant versus public in solidity functions

Using Mix, if I create a contract in the scenario with address A as a parameter, clicking on getConstant in the html below returns A as I would expected it, and I see a JS flagged transaction. If now ...
3
votes
1answer
520 views

What are the options that the web3.js solidity compiler passes to solc?

I've been using the following command to compile my contracts from CLI: solc ballot.sol --combined-json abi,asm,bin,interface > ballot.json However, the ballot.json file has a completely ...
13
votes
2answers
6k views

Convert with JS a Solidity bytes32 to a Solidity string

I have functions which are forced to return a bytes32 object, but then in my webapp I need to reconvert them to a classic string. How can I do that?
37
votes
6answers
33k views

How to convert a bytes32 to string

How can I convert a bytes32 to a string? Does anyone has a magic function or library which does it?
6
votes
1answer
275 views

Deploying new contract in transaction MIX IDE

I'm running into an issue whenever i try to create a new transaction with my newly created contract "richoCoin". It seems like its expecting the "Sample.sample()" contract. How do I resolve this?
3
votes
1answer
1k views

How to get the running instance of a Contract

I have a contract with name AuxContract and imported it in my Dapp.sol. In my Dapp.sol I have a variable of type AuxContractwhich I want to initialize with a running instance of an ...
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?
11
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
303 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
149 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
553 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
334 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
708 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
876 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
40k 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
316 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
494 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
281 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
642 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
422 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; ...