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

Can I call mapping as arguments of function?

I'd like to call mapping as arguments of function. I've tried the following code, but it returned the error. Could I call mapping as arguments as a function? mapping ( uint256 => mapping (bytes32 =...
1
vote
2answers
3k views

How to initialized struct with member variable type mapping

I have a problem with the below code, specifically samplestruct2 struct samplestruct1 { string name; } struct samplestruct2{ string name; mapping (int => samplestruct1) s1s; } ...
0
votes
2answers
2k views

An error when trying to return a static array

This compiles: This don't: Untitled:3:9: Error: Type uint8[2] memory is not implicitly convertible to expected type uint8[2] storage pointer. uint8[2] z = [255,255]; ^----------------...
5
votes
3answers
5k views

How does mapping work?

I'm trying to understand how mappings work. I've never seen anything like it before, but I'm sure many languages use something similar. Anyway, here's my code: What am I doing wrong here? Thank ...
8
votes
2answers
4k views

How to convert byte array to bytes32 in solidity

I want to know the syntax to convert a byte array to bytes32 in solidity. This is a follow up to the question- How to store Public Key in Ethereum contract? I want to retrieve the PublicKey stored ...
1
vote
1answer
897 views

invalid address sending ether from contract to EOA

I'm trying to send an ether from a contract to EOA.I'm following this tutorial, however it returned the error, "invalid address" >beneficiary.send(amountRaised); invalid address However, at the ...
2
votes
2answers
1k views

How to store Public Key in Ethereum contract?

I want to store a Public Key of an Ethereum address in a contract. What is the advisable primitive datatype to store a Public Key? Should I store as String or Bytes32? Is it secure to store a Public ...
3
votes
2answers
839 views

How to parse input data in a contract creation transaction?

When we create a contract, we always send a transaction to a empty account and with contract bytecode in input data. But sometime we need to call the constructor. So some params must be sent with ...
4
votes
1answer
341 views

What to do with smart contracts to avoid replay attacks?

I am trying to write a smart contract for Crowdsale. What extra measures should one keep in mind during smart contract development to avoid replay attacks (after the hard fork of block 1,920,000)?
3
votes
1answer
482 views

Need help understanding — web3.eth.getStorageAt

Let's say I have three state variables in my contract contract A { uint private x = 255; uint[] y; uint z; } As I understand it, x will have index 0, y index 1 and z index 2? Is it ...
1
vote
0answers
223 views

How to parse the event data [duplicate]

The event logs can be obtain via getReceipt for specific transaction. However, the data is not friendly. How can i parse those topics , data and the event name ? the receipt of a specific ...
1
vote
2answers
788 views

How to detect the balance change in solidity

In contract, there are always some storage change like token transfer. I want to detect the token transfer event. Token always store in contract mapping struct. So how can i detect the mapping change ...
10
votes
3answers
4k views

How does the EVM find the entry of a called function?

I read the source code of go-ethereum and confused about how does the EVM find the entry of a called function. As the specification said, the data field in a transaction specifies the function and the ...
3
votes
1answer
135 views

withdrawal function not working

I am writing a contract which allows a user to deposit ether into it but when it is time to withdraw only the owner can process the withdrawals and gets to decide the amount of ether taken from your ...
1
vote
0answers
126 views

Using 'now' to check time in Solidity - safe from miner manipulation? [duplicate]

I am writing a contract where I am storing the date/time using 'now' and performing date/time checks on those stored values. My questions is how do you prevent date/time manipulation from miners? If ...
2
votes
2answers
2k views

Mist error: “Could not compile source code”

Image contains the error and code i have written. I have use inheritance in my code.
3
votes
1answer
1k views

Best way of storing & querying geographical information

Lets say I'm developing a dapp that helps people redeem their beer coins by buying each other beers. They need to find each other and so they use a mobile DAPP. Bar owners are be able to add their bar ...
8
votes
2answers
3k views

Syntax for calling contract state changing methods

I've been struggling a bit with calling methods that change the state of the contract. Take, for example, the following contract: contract C { uint[] numbers; function initNumbers() { ...
1
vote
1answer
723 views

How can I log an event with indexed fields in Remix?

As you can see below, the indexed field is ignored, and the last field is set to zero: contract MyContract { event MyWorkingEvent( address thing4, address thing5, address ...
5
votes
1answer
79 views

Solidity contract - can the contract check what blockchain it is running on?

Is it possible for me to add code to my contract to check the blockchain it is running on? This is for security reasons as I only want to be running on the official Ethereum blockchain.
2
votes
2answers
821 views

nethereum - transactions are ignored or disappearing?

I'm trying to create a transaction with Nethereum as below but I cant see the result anywhere. I've checked the wallet and queried from custom client. var proposalsFunction = contract.GetFunction("...
3
votes
1answer
87 views

One contract to another contract interaction analysis

I tried contract interaction using following code: contract C2 { function aFunction(uint aParameter) returns(uint) { return (10); } } contract C1 { function call (uint aParameter) ...
2
votes
1answer
164 views

Compiling and deploying Registrar.sol in private network

I created a contract using go-ethereum console, I want to deploy registrar in private network. I found out a way to compile and deploy in https://github.com/ethereum/dapp-bin/tree/master/registrar ...
1
vote
1answer
258 views

How does EVM handle the token transfer?

This is some function in some contract. Using this type of function like transfer and transferFrom in the DAO contract, use can transfer their tokens to another account or contract. But how can ...
2
votes
1answer
206 views

Geth bug when working with address arrays?

I have the following contract that handles address arrays: contract C { address[] goodAddr; address[] badAddr; function initAddr() constant { if(goodAddr.length == 0) { ...
6
votes
1answer
753 views

How are solidity integer overflows handled?

uint8 x = 255; x += 10; Is x going to be 0 or 9?
-1
votes
1answer
103 views

I am having an issue contacting another contract from my first one

First an example, then the contract code: (it's about 200 lines all of which are kinda needed.) To explain it, this is a PoC for a special use case, the tokensHolder contract basically contains the ...
1
vote
0answers
59 views

Cannot vote on private chain. using dao tutorial

I'm trying to do a little extra with the ethereum dao tutorial on a private chain with several nodes having different etherbases. What I did is as follows, I created the contract, sent it some ...
5
votes
1answer
206 views

Help needed - Contract is deployed but execution of method always returns Zero

I have created a private blockchain and trying to create a sample contract given in https://github.com/ethereum/go-ethereum/wiki/Contracts-and-Transactions I could create, compile and even deploy the ...
2
votes
1answer
195 views

Function Declaration “Returns”

Within the Solidity Docs it's pretty much implied from various bits of example code that a function declaration needs a returns declaration to return an object, but doesn't seem to be actually ...
3
votes
1answer
534 views

Understanding SimpleStorage example from Solidity documentation

Just started learning solidity from https://solidity.readthedocs.io. Here's the code I'm trying to understand: My questions: Why does get() function has constant keyword? Is it neccessary to put ...
1
vote
0answers
65 views

Why is creating a uint8 more expensive than a uint256? [duplicate]

Assume a contract: contract A { function b() constant returns (uint8 result) { result =1; } } When I replace uint8 result with uint256 result then the creation of the contract gets ...
4
votes
2answers
1k views

How can we retrieve the transaction address of any transaction?

Once a transaction is completed on Ethereum Wallet then we can see the address of the transaction in our geth console : [ Tx("{txn address}") to: "{contract_address}" ]before mining starts. Pic ...
24
votes
1answer
15k views

Stack too deep, try removing local variables [duplicate]

When I set more than eight values as function’s return , the following error occurred. ( When the num of values is less than seven, the error didn’t occur) Could you tell me how can I get more than ...
22
votes
5answers
18k views

How can I return struct when function is called?

I'd like to return struct type User. However, when I tried the following getUser function, it returns an error. Is there any way that struct data would be returned from a function? Contract struct ...
5
votes
2answers
949 views

Create contract in Go-ethereum with Solidity, “Hello world” program

I want to create contract in go-ethereum using Solidity, I started with "Hello world" program. I create a private network: $geth --genesis private.json --networkid 1234 --datadir /home/user/...
-2
votes
1answer
36 views

Need help. 7777 [closed]

I am new to Ethereum. I have products I'd like to sell using smart contracts but I am to old and to tired in the brain to learn how to write a smart contract myself. Is there a process in place for me ...
3
votes
1answer
279 views

importing a contract does not access to its modifiers

Contract A imports Contract B and Contract B contains a modifier that I want to use in contract A. Contract A is set to inherit from Contract B, however I get the following when I try to use the ...
16
votes
2answers
9k views

Is it possible to overflow uints?

The Ethereum token tutorial has a check for a uint256 overflow. function transfer(address _to, uint256 _value) { /* Check if sender has balance and for overflows */ if (balanceOf[msg.sender] ...
2
votes
1answer
389 views

Cannot delete address value from address array (solidity)

I've run into some odd behavior of solidity. In the following example: // Omit corner cases for brevity contract C { address[] addrList; function addAddr(address addr) { addrList....
2
votes
0answers
336 views

Using contract balance as gas/tx fee for external call

Currently I have a hosted wallet Solidity contract as described below. It has a execute() method that calls another contract from a hosted wallet. However looks like call() uses the balance of the ...
6
votes
2answers
1k views

Solidity docstrings

Does Solidity offer best practice to document parameters and return values of functions. Similar to Java @param Similar to Python Sphinx :param
7
votes
1answer
6k views

Working with structure arrays in solidity

I have the following contract code example: contract C { struct A { uint256 a; uint256 b; } struct B { A ax; uint256 c; } struct C { ...
3
votes
1answer
44 views

Mix does not show the current contract state

I encouter little problems using mix. I have the following contract-code: contract C { function C() {} struct S { address creator; } mapping(string => S) M; uint x; ...
3
votes
1answer
552 views

Deleting nested structures in solidity

If a structure contains a nested structure and it is deleted, does the nested structure get deleted as well? For example, struct Point { uint256 x; uint256 y; } struct Image { Point[] ...
5
votes
2answers
1k views

How to get Ethereum Metadata? admin_getContractInfo does not exist

Is there a way to get the metadata(bytecode, ABI) of a deployed contract if you only know the address of the contract? In geth there is a function in the admin interface called getContractinfo(), but ...
1
vote
0answers
155 views

Initializing structs in solidity [duplicate]

This question is related to this one. I have a structure struct File { uint256 fileId; uint256 filePrice; } File[] files; and try to initialize it as: File newFile = File(0, ...
3
votes
3answers
934 views

Binary search in Solidity arrays

I have an array that will be subject to lookup and insertion operations. It is likely that it will increase in size considerably. Does solidity offer any means of performing efficient lookup ...
3
votes
1answer
116 views

Solidity default contract attribute/method scopes

Reading this thread, it's mentioned what the keywords public, private, internal and external represent, but what is the default specifier for methods and/or attribute contracts in solidty?
1
vote
1answer
438 views

Eris Solidity Tutorial: How to set the bank?

In the Eris Solidity tutorial, a system of a Bank and a FundManager contract are developed. In the fund manager constructor contract Bank { [Bank contract details] function setOwner(address ...