Linked Questions

1
vote
1answer
509 views

How do I write linked list in Solidity [duplicate]

In any language, I would write following: struct Node { void* data; Node* next; } ... head.next = new Node(data, null) But it seems that solidity doesn't have a concept of pointers. How ...
67
votes
3answers
22k views

Difference between require and assert and the difference between revert and throw

I was looking at the docs and Im looking for clarification on the difference between require and assert and throw and revert. assert(bool condition): abort execution and revert state changes if ...
18
votes
2answers
17k views

Can we get all elements stored in a mapping in the contract

Can we get all elements stored in a mapping in the contract using web3.js ?
8
votes
3answers
7k views

How to delete a mapping?

Fixed question: I have a mapping: mapping (bytes32 => mapping (bytes32 => bytes32[])) items; With some elements in it: items["fruits"]["apples"].push("first apple"); items["fruits"]["apples"]...
22
votes
1answer
8k views

Deploy contract from contract in Solidity

It's a common pattern to use a hub/factory contract to create multiple instances of a standard contract. It's also common to require a way to enumerate the addresses of the created contracts. Is ...
16
votes
3answers
13k views

How to loop through mapping in solidity?

I have a mapping in my contract like below: mapping (address => uint) public voterCount; To calculate the total votes, I would like to loop through the mapping and sum the uint values. How do I do ...
6
votes
2answers
5k views

Accessing a public mapping within a contract from a different contract

Consider the case where I want to get the elements of a struct via a public mapping from product contract to price contract: contract Product{ struct prod{ string name; ...
9
votes
1answer
4k views

Nested structs in solidity?

Is it possible to have a struct inside a struct? I am not sure about the data type internals, but I was basically trying to do something like (pseudo-code): library IpfsUtils { struct IpfsHash { ...
3
votes
1answer
11k views

get array.length without a getter from other contract?

Is there a way to get length of an array in an other contract without a getter? pragma solidity ^0.4.11; contract MyContractA { uint[] public myArray; function MyContractA() { ...
2
votes
1answer
4k views

Solidity for loop over a huge amount of data

I want to use a function to find all tokens of a user in solidity, so I use a for loop to iterate over all tokens and look if the addresses do match. But my function always returns zero for 10Mio ...
1
vote
5answers
3k views

How should I store user's password in a smart contract?

First I thought I could easily use private like: mapping (address => bytes32) private userPassword; and so just check if the entered password is right: function enter(bytes32 password) { if (...
3
votes
1answer
4k views

Store addresses in array or mapping?

My contract currently serves an array of addresses to a front-end: address[] public addresses; function getAddresses() public view returns (address[]) { return addresses; } I'm concerned about ...
1
vote
1answer
3k views

Pushing/Pulling data from data storage contract

Is there any way I can have a smart contract that stores the a value and name and then is callable from another smart contract? Something like this..(but that works) Contract D { struct Document{ ...
2
votes
2answers
2k views

Payable: Sent - Hold amount - Sent_back mechanism (Refund)

[Q] When following transaction get called: Bank.pay({"from": eth.accounts[0], "value": 1});, who retrieves the money, does the owner of the contract? (Sorry I get lost who actually gains the money). ...
7
votes
4answers
527 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 ...

15 30 50 per page