Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

1
vote
2answers
759 views

How do I call a Contract function from a required Account

I am using geth on a private chain. I have a Solidity function on a contract as follows: function check() public constant returns (string) { // if caller is not who it should be don't do ...
2
votes
1answer
710 views

How can I declare a string value more than 20 bytes in Solidity?

I'd like to declare a string value more than 20 bytes in Solidity. I use address type, but it only contains 20bytes. Could you tell me how to solve the problem?
3
votes
1answer
457 views

Can I check the number of digits in solidity?

Can I check the number of digits in solidity? I'd live to validate input by ethereum. Can't I achieve it?
11
votes
2answers
3k views

In solidity, how can you set a bytes variable to empty

I tried this contract MyContract{ bytes public data = 0x3333; function clearData(){ data = 0x; } } But solc doesn't like me trying to set data to 0x
3
votes
0answers
67 views

Can a solidity event be logged successfully before a throw? [duplicate]

If I have the following code in a solidity contract function: event_logEvent(); throw; Does the event get logged correctly into the blockchain or does the throw also revert all the events?
15
votes
4answers
14k views

Conversion of uint to string

I am trying to convert uint to string in solidity. Is it possible to convert? if so how can I convert it? Convertion to base 10 is prefered, but in hexadecimal might also be helpful.
4
votes
1answer
478 views

Is the address of a Smart Contract fixed?

I would like to know if the address of the smart contract is fixed. I want some privacy for my application, so I would like to change the sending address and receiving address each time the smart ...
4
votes
1answer
369 views

Can a contract read the address of past miners?

I am trying (in solidity) to write a contract that needs some statistics on the past few miners. E.g., who mined the last 100 blocks. I know that for the current block I get the address as explained ...
4
votes
0answers
86 views

Looking for working example of web3.getStorageAt() API usage [duplicate]

The documentation at http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage commonly linked to in other questions does not go into enough detail to replicate ...
8
votes
5answers
9k views

What is the cause of the error: Expected import directive or contract definition

I'm working on the tutorial at https://www.ethereum.org/dao and I'm getting the following error: 1:5: Error- Expected import directive or contract definition. function owned() { ^ When I get ...
10
votes
2answers
5k views

Solidity functions - private visibility

Is the following function parameter (string name) only visible to the owner contract itself? function myFunction(string name) private returns (bool) { return true; } So nobody can read / see ...
13
votes
1answer
2k views

What are the attributes of the `msg` object and how can I list them?

I know msg.sender exists, it gives the address of the sender. What other attributes are there and how can I list them / where are they defined?
17
votes
1answer
2k views

Are events permanently stored and reliably available to contracts in the future?

I've seen this forum post about using Ethereum as an event store: Events in Solidity, using blockchain as eventstore. However, it doesn't seem conclusive. For instance it says: I confirmed with ...
3
votes
1answer
125 views

Stack to deep workaround for object “ instantiation ”

I'm have an object with around 25 fields in it. int idOfObjectTracker; mapping (uint => object)listofobjects; struct object { string _1; string _2; ... string _25; } i'm trying to " modifiy ...
8
votes
1answer
6k views

How to convert a uint256 type integer into a bytes32?

Since both types, uint256's and bytes32's space are 2^256. How to map an uint256 type integer into bytes32 type in Solidity ?
4
votes
1answer
335 views

Contract code not executing from web3, works from Mist

I seem to be having a problem w/ contract code not executing when called from web3 (works when called from mist). The Eth goes to the contract, so I know it is making the call at least. I am calling ...
5
votes
1answer
1k views

How to import Oraclize module?

I am trying to follow an Oraclize example, with this source code and compile it using Mist: /* Kraken-based ETH/XBT price ticker This contract keeps in storage an updated ETH/XBT price, ...
2
votes
0answers
459 views

Can you make HTTP calls with Solidity? [duplicate]

I want to create a very close to random number generator for a smart contract which I would like to do HTTP calls to webservices to do. Is that able to be done with Solidity? I am just digging into ...
14
votes
3answers
4k views

send VS call - differences and when to use and when not to use

Can somebody please explain the differences between using a send and call for contracts and when to use and not use these different methods? For example : msg.sender.send(number); msg.sender....
4
votes
1answer
893 views

Events doesn't fire executing transaction with web3 in testrpc

I'm executing the basic token contract found at https://ethereum.org/token: contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); } ...
3
votes
1answer
231 views

Ballot contract: Why `voters[chairperson]`?

In the Ballot contract from the Solidity documentation, the Ballot function assigns voters[chairperson].weight = 1 What does that mean? Out of the set of voters, we find the chairperson (like in a ...
11
votes
1answer
2k views

How do I construct a call to another contract using inline assembly?

I would like to call a contract and deal with the return values manually using EVM assembly in Solidity. For example, this should simply add two numbers together. contract Test1 { function add(...
4
votes
5answers
6k views

Solc --version: command not found

I'm trying to use solc with no success. I download solc with npm install solc but when I run solc --version the console output is: command not found. If I list packages npm list I'm able to see ...
6
votes
1answer
608 views

Is address.send() not vulnerable for the recursive call attack?

If my dapp sends ether to another address via the send() method is it not vulnerable for the recursive call attack due to the limited amount of gas of 21000? Or should I still take precautions?
3
votes
2answers
674 views

How to access events logs in ethereumJ ( java )

Accessing event logs from javascript is easy and straight forward, however I am trying to access the logs from the Java client. Any example code would help
1
vote
0answers
116 views

how can i make multiple users having different addresses when they register to my contract?

I want to create a register page where i want users to register and after registration they should get different addresses so that i can fetch their details by address.
3
votes
1answer
106 views

How to handle remaining funds after a crowdfund closes (from the tutorial)

The tutorial crowdfunding app has the following function: /* checks if the goal or time limit has been reached and ends the campaign */ function checkGoalReached() afterDeadline { if (...
8
votes
1answer
2k views

Callstack attack

If my contract has a payout function like this address bossAddress; address employeeAddress; uint256 bossSalary; uint256 employeeSalary; function payout (){ if (msg.sender==bossAddress){ ...
4
votes
1answer
189 views

Is the ethereum.org/dao contract vulnerable to recursive call attacks?

Does putting p.executed = true after p.recipient.call() make this vulnerable to recursive calls? function executeProposal(uint proposalNumber, bytes transactionBytecode) returns (int result) { ...
5
votes
1answer
273 views

Where is 'Token 0.1' standard defined?

In an example on https://www.ethereum.org/token : /* Public variables of the token */ string public standard = 'Token 0.1'; enter preformatted text here Why 'Token 0.1'? Where is the standard ...
10
votes
1answer
864 views

Writing secure Smart Contracts in Solidity?

With the DAO hack, it becomes even more important for developers to write secure smart contracts and be aware of pitfalls. Are there any good reference points/links which can describe the best ...
2
votes
1answer
2k views

Finding the index of an array element

I posted a question 1 day ago asking if it was possible to have multiple coin types in a single contract and I am trying to implement the answer I received. Is it possible to have multiple coin types ...
5
votes
1answer
628 views

Contract size limit after creation?

For example, lets consider the basic example of issuing a token: ...string public symbol; uint8 public decimals; uint256 public totalSupply; mapping (address => uint256) public balanceOf; ...
11
votes
1answer
2k views

How does the stack depth attack make a send() silently fail?

From a blogpost on security from Christian Reitwiessner: Because of the maximal stack depth of 1024 the new bidder can always increase the stack size to 1023 and then call bid() which will cause the ...
1
vote
1answer
243 views

Parsing transaction receipts in Solidity similar to eth_getTransactionReceipt code

I would like to have the functionality in my Solidity contract that when a user sends a transaction with a transaction hash, the contract parses it to get information of the timestamp etc. The best ...
7
votes
3answers
7k views

Parse JSON in Solidity

How can I parse JSON in solidity? The idea is to have a function or similar which is able to parse JSON inside a Solidity contract. With a simple JSON object (only key value strings, like {'A': 'a', ...
3
votes
1answer
430 views

During deploying contract in go ethereum how other contract gets to know where other one is when they are inherited?

when we deploy two contracts in go ethereum and one is inherited by the other ,when we deploy contracts differently how other contracts gets to know where the other contract is and it is able to ...
1
vote
0answers
71 views

Create new contract from Relay

Currently I import a contract into another one, wich allow me to create a new contract based on the imported one. I would like to manage versions of the imported contract, so a RelayContract (or ...
3
votes
1answer
571 views

Is it possible to have a mapping with a hash as key?

Is it possible to have a mapping in Solidity with a hash as key? For example: mapping (hash => uint) hashToInt; If not, is there any way to group some information and put it as a key of a ...
6
votes
2answers
480 views

Checking the blockchain within Solidity contract

I want my contract to check a given range of blocks and see whether there are any transactions between a given pair of addresses. Is this possible to do in Solidity? Otherwise how would I do it?
25
votes
4answers
5k views

Error while compiling: Stack too deep

When trying to compile, I am getting the following error: "Internal compiler error: Stack too deep, try removing local variables." Is there any way around this? I'm not sure if I'll be able to ...
9
votes
5answers
1k views

BNF grammar definition for Solidity

I scoured the Mix and Solidity repos for something like a formal definition of the language's grammar, so that one may generate parsers using tools like GrammarKit, but couldn't find anything. Any ...
5
votes
1answer
501 views

Contract 'throw' - ether sent by the contract also reverted?

If a contract throws a exception (using 'throw') is any ether sent by the contract to other contracts or external accounts also reverted? I understand that any contract callers have the ether value ...
5
votes
1answer
305 views

Are mutable data structures expensive (gas, Solidity)?

I was planning on implementing a heap data structure for efficient popping of the highest valued node. I am wondering if it is expensive gas-wise to constantly move values around ("bubble up") to ...
3
votes
2answers
3k views

If i am writing two contracts A,B and extending one with other then can i use methods from contract A in contract B when i am deploying?

If i am having two contracts extending one with other then can i use methods available in one contract in another when i have deployed.We have to take them in one file or have to deploy differently ...
14
votes
1answer
2k views

How much computation can be done in a fallback function?

Simply sending Ether to a contract, will run the contract's code. In Solidity, this code maps to what it calls the fallback function. How much work can be done in a fallback function?
5
votes
1answer
1k views

How do you get a string value from msg.data in the fallback function?

Im trying to do what The DAO did and do something when a sender sent money to my contract address. But im not sure how to. The something I want to do is to just create a new user in a mapping with the ...
4
votes
2answers
478 views

Struct array not updated, function call returns old values

I have created following method in contract with the strcuture contract testContract{ Student[] public students; struct Student{ string name; uint256 age; } function addStudent(...
3
votes
0answers
108 views

Solidity benchmarking metrics [duplicate]

I am trying to figure out the best ways of benchmarking Solidity contracts. As with normal benchmarking, I presume one would basically want to measure computational effort and storage overhead: gas ...
14
votes
2answers
4k views

Can Solidity function modifiers access function arguments?

I would like to have a modifier that looks like this: modifier restrictTargetType(uint contractType) { if (contractTypes[target] != contractType) { throw; } _ } Where target is an address ...