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
2answers
895 views

How do we manage accounts for users

I understand there are accounts and we unlock them in geth/eth. If we are providing a service to a user community what is the design pattern envisaged to enable users to perform transactions under ...
3
votes
2answers
809 views

Contract creating another contract in a single source file

When deployed as a single source file is the address stored in variable creator = TokenCreator(msg.sender) within function OwnedToken referring to the address of the contract TokenCreator or the ...
5
votes
1answer
530 views

Invoking internal function with enough gas

I'm new to ethereum and getting my hands on contracts (in solidity). I think I have a very simple question but I can't for the life of me find the answer. Simply put: How to I invoke an internal ...
6
votes
1answer
2k views

How do I manage unlocking accounts in a test in Truffle

I have a test that exercises a contract function across different accounts. How do I unlock these accounts in the context of the test? contract('MyContract', function (accounts) { it("should ...
47
votes
3answers
11k views

Why does uint8 cost more gas than uint256?

contract A { uint8 a = 0; } costs 20150 + 2000 gas during creation. as compared to contract A { uint a = 0; // or uint256 } costing 5050 + 2000 gas during creation It is odd that a variable ...
5
votes
2answers
255 views

Running contract CrowdFunder in Mix and function modifier causes - Solidity exception (bad jump)

I'm experimenting with contract CrowdFunder which I found on the net https://github.com/nemild/learnxinyminutes-docs/blob/solidity/solidity.html.markdown and I'm getting an error Solidity exception ...
11
votes
2answers
22k views

How to get current time by solidity?

I'd like to describe time like Apr15th 10:00AM . I know how to describe time range as follows, but I am not sure how to call date of time. Could you tell me about it if you know? 1 == 1 second 1 ...
9
votes
1answer
2k views

Does Solidity's constant keyword do anything?

It seems that the purpose of function foo() constant {} is to indicate that a function does not change the contract's state. And yet, as it states here, the compiler doesn't actually enforce this. So ...
5
votes
1answer
563 views

Does bloom filter library for use in Solidity exist? [closed]

Since there are strict storage and computational limits forced by a VM some operations for enterprise-level contracts are impossible. Is there some Bloom filter implementation available in existing ...
12
votes
3answers
4k views

How does Ethereum cope with division of prime numbers?

I have seen this question here about representing decimals in solidity, and although of course the answer is that 'msg.value' is always in Wei, this got me thinking about how Ethereum handles division ...
4
votes
2answers
847 views

How to easily share Solidity code so that others can test it?

Say you have some Solidity code and something doesn't work and you'd like for somebody to take a look at it and do some quick tests. What is an efficient way to share Solidity code with others?
2
votes
1answer
2k views

Compare ether values in contracts

in a contract: msg.value is an amount in wei, and I can write 2 ether == 2000 finney as per the docs. Is there a simple way to compare an amount in wei (specifically msg.value) with a concatenation ...
31
votes
4answers
18k views

How can I represent decimal values in Solidity?

I just started writing some solidity and I noticed that there are no decimal values such as double or float. What do you guys do when you need to return send to a wallet let's say 1.57 ether? Or when ...
3
votes
1answer
118 views

Can browser-solidity access contracts values with the in memory tester?

I was reading an interesting answer and wanted to make a quick test in browser-solidity. My contract code is below and I'd just like to get the string I passed in the constructor. contract ...
2
votes
2answers
614 views

What programs should a beginner solidity developers use?

At this time I write code in the 'Solidity realtime ethereum compiler and runtime' chrome extension. And I test my codes on the main net. Are there better programs or how can I get test ether?
3
votes
2answers
3k views

How do you get events from a function in another contract?

I have two contracts : // contract #1 contract eXample { // intizializer function eXample{ ..... } //creating the Event event MyEvent(uint x,uint y,uint z); function doSomething{ ........
14
votes
5answers
37k views

Where can I find some Solidity / Smart Contract source code examples? [closed]

Is there an easy to access list of Solidity / Smart Contracts / Dapps source code examples? Related information: Is there a list of DAPPS that are already useable? Where can I learn how to develop ...
9
votes
2answers
3k views

Finding and Using Solidity Libraries (ie. Math functions)

How do I find and use any existing Solidity libraries like you might in Javascript? For example, Math functions: How do I implement the equivalent of Math.sqrt(x) in a solidity function? Related: ...
19
votes
6answers
4k views

Can I square root in Solidity?

Is it possible to square root 50 or should I use 7.071067. I'm very new in programming and I also understand that it's possible in all other languages, but I'm not able to see where the limitations ...
20
votes
4answers
9k views

How does one contract send ether to another contract with more than 2300 gas?

I want one contract to collect a certain amount of finney before sending it to another contract, but I can't simply send in with C2.send(thisMuch). function() { Dividend m = Dividend(dividendAddr)...
3
votes
1answer
680 views

What is the code to allow a contract to automatically sell specific quantities of tokens at different prices?

I would use the below code to sell my tokens at a specific price (manually set by me). But, how can you allow a contract to automatically sell the first 10 tokens at 0.1 ETH, the next 20 at 0.15 ETH ...
2
votes
2answers
109 views

Why does my copy of Mix on OSX have an ancient version of Solidity?

I just downloaded the latest version of Mix, and noticed it doesn't support inline assembly. Clicking on Mix -> About Mix, I see it's running version 0.2.2 of Solidity. Why is it running such an old ...
44
votes
8answers
24k views

How to quickly test a Solidity function?

There are snippets and functions of Solidity code provided on this Ethereum Stack Exchange and other sites. What are ways to quickly test them, possibly debug a little, and play around?
6
votes
1answer
418 views

Getting segmentation fault while compiling solidity contract

Getting segmentation fault when compiling a simple contract on geth on OSX Yosemite web3.eth.getCompilers(); ["Solidity"] source = "contract test { function multiply(uint a) returns(uint d) { return ...
13
votes
2answers
892 views

Why does a simple function returning a 'string', call another contract?

This trivial contract: contract Test { function test() returns (string) { return "foobar"; } } Results in assembly code output (in the solidity web compiler) for the function 'test' ...
20
votes
3answers
26k views

Call function on another contract

I've created a contract called "Name" which I've deployed to the testnet. this function just register some text for the user and display it back. My contract is: contract Name is mortal{ ...
18
votes
2answers
1k views

What does bytecode of blank contract do?

When I compile a blank contract: contract A {} with solc --optimize --optimize-runs 300000 --opcodes test.sol I get: PUSH1 0x60 PUSH1 0x40 MSTORE PUSH1 0x6 DUP1 PUSH1 0x10 PUSH1 0x0 CODECOPY ...
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; ...
50
votes
3answers
33k 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
767 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
12k 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
469 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
615 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" + " /// ...
26
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
633 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?
38
votes
8answers
34k 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?