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
21 votes
2 answers
10k views

How do I find out the solidity compiler version I am using?

Specifically, while using Mist. When I create a contract via the Mist GUI, I want to then be able to verify the source code over at Etherscan. However, Etherscan requires that you provide the ...
Micah Zoltu's user avatar
4 votes
1 answer
171 views

Contract to contract send [duplicate]

I have a contract that sends a small fee to the owner. It works perfectly fine but when I change the owner to an address which contains another contract it always causes an error when viewed on the ...
Philip Kirkbride's user avatar
5 votes
2 answers
920 views

What does "code and ABI that are needed by web3" refer to in solc / nodejs

var input = "contract x { function g() {} }"; var output = solc.compile(input, 1); // 1 activates the optimiser for (var contractName in output.contracts) { // code and ABI that are needed by web3 ...
kcruz305's user avatar
0 votes
1 answer
339 views

Uncaught Reference Javascript Error when submitting data via html to contract

I created a contract (Freight) using the "ratings" tutorial template. The Freight contract is meant to store values entered in the html page (input.html) and submitted. Just like the "ratings" ...
Kizito's user avatar
  • 779
6 votes
1 answer
1k views

How to send bytes in combination with array to contract

I see strange behavior when I try to execute some test contracts. I have made 2 test contracts, contract TestContract1 { uint public n; uint public testValue1; bytes6 public ...
hatemp's user avatar
  • 61
6 votes
2 answers
1k views

Make data from smartcontracts / events only visible for certain address/users

I Have an use case where i need : 1- My data not to be visible to the public. 2- To be able to revoke my clients/users rights to view said data from my smart contract. As anyone done that before ? ...
jayD's user avatar
  • 2,462
28 votes
1 answer
11k views

What is the cheapest hash function available in solidity?

AFAIK there are 3 hash functions to choose from in solidity (sha3, sha256, and ripemd). sha3 is native while the others use precompiled contracts. Which one of these is cheapest (in terms of gas)?
Akhil F's user avatar
  • 1,918
20 votes
3 answers
7k views

What are some examples of how inline assembly benefits smart contract development?

A lot of people have expressed excitement at the potential of using inline assembly in smart contracts. After seeing this comment on reddit I'm curious to see some basic (and more advanced, if you ...
Joël's user avatar
  • 1,710
75 votes
7 answers
123k views

How do you get a json file (ABI) from a known contract address?

I want to watch a Solidity contract using the Mist browser. I know how to do that and it needs the address and the json. I have the address, but I don't have the json. I do have the source code. Can ...
Thomas Jay Rush's user avatar
8 votes
2 answers
11k views

Calling public array of structs using web3

Good day. I've got an array of structs such as: User[] public users; struct User{ uint idNum; string name; address userAddress; } And I'm trying to get the array of users with web3.js ...
shultz's user avatar
  • 1,091
29 votes
2 answers
5k views

What is the merit of creating new smart contract languages like Solidity instead of using other languages?

What is the pros and cons of creating new languages like Solidity for smart contracts instead of using other computer languages like Golang or Python?
Satoshi Nakanishi's user avatar
3 votes
2 answers
977 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 ...
Interition's user avatar
3 votes
2 answers
906 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 ...
Zach_is_my_name's user avatar
5 votes
1 answer
630 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 ...
Thomas's user avatar
  • 51
6 votes
1 answer
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 ...
Interition's user avatar
74 votes
5 answers
28k 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 ...
uzyn's user avatar
  • 1,100
5 votes
2 answers
281 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 ...
Bogdan's user avatar
  • 397
23 votes
3 answers
47k 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 ...
Toshi's user avatar
  • 2,357
9 votes
1 answer
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 ...
redsquirrel's user avatar
6 votes
1 answer
873 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 ...
Aldekein's user avatar
  • 402
13 votes
3 answers
5k 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 ...
T9b's user avatar
  • 1,185
4 votes
2 answers
1k 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?
euri10's user avatar
  • 4,640
2 votes
1 answer
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 ...
euri10's user avatar
  • 4,640
46 votes
6 answers
43k 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 ...
sfrj's user avatar
  • 782
3 votes
1 answer
127 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 ...
euri10's user avatar
  • 4,640
2 votes
2 answers
641 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?
Sileniced's user avatar
  • 537
4 votes
2 answers
4k 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{ ........
user697's user avatar
  • 2,166
14 votes
5 answers
40k 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 ...
12 votes
2 answers
5k 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: ...
Bill LaPrise's user avatar
27 votes
6 answers
12k 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 ...
Sileniced's user avatar
  • 537
21 votes
4 answers
10k 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)...
Sileniced's user avatar
  • 537
3 votes
1 answer
712 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 ...
Virgil Fotachi's user avatar
2 votes
2 answers
118 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 ...
Nick Johnson's user avatar
  • 8,144
54 votes
8 answers
31k 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?
eth's user avatar
  • 85.4k
6 votes
1 answer
573 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 ...
Makoto's user avatar
  • 481
14 votes
2 answers
969 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' ...
Nick Johnson's user avatar
  • 8,144
21 votes
2 answers
32k 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{ ...
shultz's user avatar
  • 1,091
18 votes
2 answers
2k 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 ...
Brian's user avatar
  • 243
9 votes
1 answer
2k 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; ...
ChrisH127's user avatar
  • 178
73 votes
3 answers
68k 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 ...
user697's user avatar
  • 2,166
1 vote
3 answers
3k views

Syntax highlighting for Solidity VS Code extension not working on linux

Even if the extension installation completes correctly, syntax highlighting does not work.
dotnetjunkie's user avatar
11 votes
1 answer
11k 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 ...
mrAkax's user avatar
  • 173
7 votes
2 answers
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?
juro's user avatar
  • 173
5 votes
2 answers
6k 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 ...
zunior's user avatar
  • 1,312
7 votes
4 answers
1k 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 ...
Philip Kirkbride's user avatar
44 votes
1 answer
23k 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....
billett's user avatar
  • 1,255
9 votes
2 answers
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) {...
Kizito's user avatar
  • 779
7 votes
3 answers
4k 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 "...
Walt D's user avatar
  • 391
4 votes
1 answer
853 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.
Matias's user avatar
  • 1,109
11 votes
1 answer
676 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 ...
Ivan's user avatar
  • 113