All Questions

Filter by
Sorted by
Tagged with
31
votes
1answer
40k views

How to initialize an empty array and push items into it?

Here's my function: function Test() constant returns (uint[]) { var myArray = uint[]; myArray.push(123); return myArray; } Here's an error I get in the solidity online compiler: ...
31
votes
3answers
5k views

What is a replay attack?

During the launch of the frontier network, users were cautioned not to reuse keys from the Olympic testnet in order to prevent "replay attacks". What is a replay attack, and why would re-using a key ...
31
votes
1answer
12k views

Is there a table of EVM instructions and their gas costs?

The EVM instructions are in the yellow paper, or they are summed up in this answer. But their gas costs are not there. Where can I find a list of all instructions with their associated gas costs?
31
votes
1answer
9k 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....
30
votes
3answers
13k views

How to write an optimized (gas-cost) smart contract?

As we all know, there are many factors that determine a good smart contract, such as: Security: it has minimal/zero vulnerability so they cannot be exploited by an adversary. Immune to Attacks. Cost:...
30
votes
4answers
36k views

How to call my contract's function using sendTransaction

This may be a very basic question, I don't know why but I am unable to find correct solution to how can I call my contract's method using sendTransaction. I have a transfer(address, uint256) function ...
30
votes
2answers
18k views

What is the ethereum transaction data structure?

I'd like to know the detail of the Ethereum transaction data structure. What data is stored in transaction?
30
votes
2answers
26k views

How does Mapping in solidity work?

I went through the Crowdfunding example in solidity where i encountered the following: contract Crowdfunding { struct CampaignData { address recipient; uint contributed; uint goal; ...
30
votes
2answers
9k views

Why do Solidity examples use bytes32 type instead of string?

In many Solidity examples I read that use strings for parameters or return values, I see they are typed as bytes32 although there's a string type. What is the real reason for that? Thanks.
30
votes
3answers
4k views

Concurrency patterns for account nonce

The account nonce is the only element in the transaction structure that prevents replay attack (as explained in this very good answer). It essentially forces sequentialisation of an account's ...
29
votes
6answers
26k views

How to check my sync status on Geth 1.5.5, Raspberry Pi 3

Have a Geth 1.5.5 node running on a raspberry pi 3. When I type in sudo systemctl status geth I'll get ever changing time and block information. Neat, but how do I know when I am synced up? Is ...
29
votes
4answers
22k views

Returning a struct and reading via Web3

I am storing data in my contract using a mapping of structs. For examples sake, say I'm storing employee info (name/address/salary), mapped by their employee ID. Via a web front-end, I'd like to be ...
29
votes
7answers
21k views

What are the differences between Bitcoin blockchain and Ethereum blockchain?

Ethereum has been debated in the bitcoin ecosystem and was criticized. In order to understand better both projects, what are the main differences between BTC and ETH regarding the blockchain ...
29
votes
3answers
13k views

What are the limitations to estimateGas and when would its estimate be considerably wrong?

web3.eth.estimateGas and JSON-RPC estimateGas can be used to see how much gas should be specified for a transaction, before crafting the transaction. Since it is an estimate, are there any ...
29
votes
3answers
14k views

How to create a Dapp from scratch on Ethereum?

Let's say we have someone who knows about blockchain but who doesn't have any background in blockchain-based application. That person wants to code an ethereum-based Dapp (decentralized application) ...
29
votes
2answers
11k views

How to encrypt a message with the public-key of an Ethereum address

I am writing some code in nodejs/browser. I have successfully created ethereum-addresses with the secp256k1-library. I was also able to sign and verify messages. Now I want to encrypt/decrypt a ...
29
votes
4answers
11k views

How do I decrease the difficulty on a private testnet?

I've created a private test network. On the genesis.json file, I've changed the difficulty to 1. Yet, mining a block still takes hours on my CPU. I suspect that is due to some configuration related to ...
29
votes
3answers
5k views

What is the distinction between libp2p, devp2p and RLPx?

What is the distinction between libp2p and devp2p? Do they refer to the same thing? How are they related to RLPx? In the libp2p whitepaper, dated Nov 2014, they appear to be the same thing: libp2p ...
29
votes
5answers
6k views

How to detect if an address is a contract?

I'm interested in knowing whether any particular address is a contract address or a standard address. There have been similar questions on the topic, but I'm not looking to detect whether an address ...
29
votes
5answers
17k views

web3: How do I get past events of myContract.myEvent?

I use the following JS code to get notified of Solidity events and it works well for incoming new events: myContract.myEvent().watch((error, result) => { if (error) console.log('Error in ...
29
votes
3answers
12k views

Ethereum Merkle Tree Explanation

Here is my basic understanding about how Ethereum stores transactions A hash is generated for each transaction Then pairs are selected and a hash is generated for each pair This way the last ...
29
votes
1answer
17k views

How to update a deployed smart contract? [duplicate]

I've started developing smart contracts with Truffle and when I edit a contract I always redeploy it by adding another migration script. There are two things that I wonder about: Is this the way it ...
29
votes
4answers
26k views

Can I download the whole blockchain from somewhere?

Bitcoin used to offer sharing/downloading a bootstrap.dat which contains the whole blockchain. Are there alternatives to getting it trickling through the peer-to-peer network? Can I just download it ...
29
votes
1answer
15k views

How does the delegatecall method work to call to another contract's method?

I'm trying to figure out how to use the delegatecall method on a contract address in a contract to call a function in a separate contract. I know Libraries are the higher level interface to use but I ...
29
votes
1answer
14k views

What does v, r, s in eth_getTransactionByHash mean?

In Ethereum JSON-RPC I found the return is: Returns Object - A transaction object, or null when no transaction was found: hash: DATA, 32 Bytes - hash of the transaction. nonce: QUANTITY - the number ...
28
votes
4answers
32k views

payable() function In solidity

I have read many examples of payable functions, but I didn't understand any of them. Also, they talked about modifier in payable. My questions are: What exactly does payable() function do? ...
28
votes
3answers
6k views

Can a contract safely rely on block.timestamp?

How safe is it to use block.timestamp as contract expiration time? If a miner provides an incorrect timestamp in a block header, how much can it be off before it is rejected by other nodes? Is there a ...
28
votes
2answers
9k views

web3.js execution - server vs browser

I'm a little bit far from web development, so I have one misunderstanding. As far as a know, node.js code should be run at server side and web3.js is designed to work at server side (not sure), ...
28
votes
10answers
11k views

How can you handle an expected throw in a contract test using truffle and ethereum-testRPC?

Is it possible to write a test using truffle that attempts to confirm that a throw occurs in a contract? For example, if I had a contract with function... contract TestContract { function testThrow(...
28
votes
4answers
14k 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 ...
28
votes
5answers
9k views

How can I sign a piece of data with the private key of an Ethereum address?

I would like to use the key pair of one of my Ethereum accounts to sign a piece of data. How can this be done?
28
votes
3answers
18k views

How can I make new account by JSON-RPC?

I'd like to make new account by JSON-RPC.I've checked the wiki of Ethereum, however I could not find out how to do that. I've found call existed accounts, but it isn't what I want. eth_accounts ...
28
votes
3answers
24k views

How can I view event logs for an ethereum contract?

After reading the this post, it seems like I should be able to access the logs of events that have been called on an Ethereum contract. The section I am interested in is Option 3 which is using event ...
28
votes
2answers
10k 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 ...
28
votes
3answers
21k views

How to explore all transactions for a given account?

After beeing able to check account balances, I am looking for a method to list all transactions for a given Ethereum account through json-rpc protocol. I haven't found any method suitable for that on ...
27
votes
7answers
27k views

web3.eth.contract is not a function when making contract

Whenever I try and make a contract, I get: web3.eth.contract is not a function I'm using this code: const path = require('path'); const fs = require('fs'); const solc = require('solc'); ...
27
votes
1answer
13k views

Ways to see if address is empty

Is owner > 0x0 a good way to test if an address owner was set in Solidity? I am not sure if this could break something in the future and if there are better ways to see if the address was set. What ...
27
votes
4answers
7k views

Does every node execute the contract code for each transaction?

This question was asked on Reddit a while ago: When a node sends a transaction to the network and has the receiver as a contract, does every node execute the contract bytecode with the inputs to ...
27
votes
4answers
21k views

Is the block.timestamp value in Solidity seconds or milliseconds?

I'm looking to use block.timestamp in one of my contracts and I want to know whether the block.timestamp is seconds like in Python or milliseconds like in Java or some other value? Also, is it safe ...
27
votes
2answers
20k views

What exactly is the Nothing-At-Stake problem?

What exactly is the Nothing-At-Stake problem in Proof-of-Stake consensus networks? While I understand what the nothing at stake problem means, I do not really understand the security implications. ...
27
votes
6answers
15k views

How to compile Solidity contracts with Geth v1.6?

I tried to compile the following contract within geth: pragma solidity ^0.4.8; contract Test { uint256 public value; function Test() { value = 123; } } using the following ...
27
votes
6answers
9k views

How to make miner to mine only when there are Pending Transactions?

As of now the geth miner running on my system mines even empty blocks. All i wanted is miner should mine only when there are Transactions to mine, after mining the miner should immediately sleep. ...
27
votes
5answers
39k views

Can't send transaction — “Exceeds block gas limit” or “Intrinsic gas too low”

I'm trying to send Ether using geth 1.3.5, like this: eth.sendTransaction({ from: eth.accounts[0], to:'0x[ADDRESS_HERE]', value: web3.toWei(5, "ether"), gas:21000 });` And I'm getting "...
27
votes
2answers
10k views

Can I save structs in a Mapping?

Is it possible to store structs in a Mapping or any dynamic memory structure in my Solidity SmartContract?
27
votes
9answers
44k views

How to get private key from account address and password?

What I have 1. I am able to create new account with personal.newAccount() method of web3 api. 2. I am working on my private blockchain. 3. geth node start with following command:- geth --datadir ~/...
27
votes
2answers
3k views

Is it a good practice to log an event every time I throw in Solidity?

In Solidity (0.3.2) I am aware that there is no way to throw specific exceptions. (Everything is an invalid JUMP error.) It seems beneficial to have a way to log specific errors. Does it make sense to ...
27
votes
1answer
4k views

What is coinbase?

What is the ethereum coinbase? I understand it is an account, but what makes it different? Is it the same as Etherbase? I've read it's the "default account for your console session." Does that mean, ...
27
votes
3answers
3k views

Is Ethereum secure against an attack by quantum computers?

Does Ethereum implement Post-quantum cryptography? Or will the network break once a malicious actor gains control of an effective quantum computer?
27
votes
1answer
8k views

Cannot perform write functions in smart contract - invalid address?

I have the following simple smart contract... contract SimpleStorage { uint storedData; function set(uint x) { storedData = x; } function get() constant returns (uint retVal) ...
27
votes
1answer
10k views

How can I verify a cryptographic signature that was produced by an Ethereum address key pair

If I have a cryptographic signature from an Ethereum address key pair, how can I verify that signature?

15 30 50 per page