Paul S
  • Member for 5 years, 11 months
  • Last seen more than a month ago
How can a DApp detect a fork or chain reorganization using web3.js or additional libraries?
Accepted answer
19 votes

Here's code that waits specified number of blocks and verifies the transaction receipt is still valid. If a fork occurs and the replay fails, the receipt check should fail and the callback will call ...

View answer
How can I debug a smart contract?
15 votes

Those are all good tools, but I have found the logging events is much easier method for debugging, plus if you are doing anything with money you want to keep a record of what happened. In Solidity, ...

View answer
How do I parse the transaction receipt log with web3.js?
Accepted answer
14 votes

Tim: Thanks so much for the pointer. You forced me to finally understand some of the internals of web3.js. I found a cleaner way to do this that covers all the corner cases of the actually fairly ...

View answer
How do I know when I've run out of gas programmatically?
Accepted answer
12 votes

There currently isn't a clear signal that you've run out of gas. A log message is being added to some future release. Currently what I do is check to see if gasSent == gasUsed. This requires your ...

View answer
How to create a data structure in Solidity with no limits on size?
Accepted answer
9 votes

Similarly, Solidity Arrays are fixed to the size you initialize them with. Solidity arrays are not fixed size. Here's an example snippet from a contract I use to test gas optimization: contract Gas ...

View answer
How can I completely automate a Docker image and Dockerfile for a geth test network
9 votes

Here's the steps I used to create a Docker image that recreates a consistent test environment: Create a Docker file (see listing below) with empty geth data directory and files as noted in the Docker ...

View answer
constant versus public in solidity functions
Accepted answer
8 votes

I'm not sure which part of the system assumes this (web3.js?), but if you don't declare a a function as constant it's assumed it's going to change contract state and thus sets up a transaction. The ...

View answer
How does Ethereum regulate the time between blocks?
8 votes

If you are using geth here's a patch that I use to accelerate mining. You could probably modify it to decelerate mining if you wish. (I'm curious why you wish to go slower). In any event, I think ...

View answer
How do I access member variables of a contract from web3.eth?
Accepted answer
7 votes

public members of Solidity contracts have an automatic getter method created, it would look something like this: contractInstance.stage(callback) For general API on contract methods see See Calling ...

View answer
How to spend ether from multiple accounts?
6 votes

The reason I'm asking this is because I need to accept Ether payments in my system and I would like to generate a unique account for each deposit, Don't put ether in raw accounts on a client node, ...

View answer
IF statements in Solidity not behaving as expected
Accepted answer
6 votes

Solidity has a syntax sort-of borrowed from Javascript. This means it uses braces to denote groups of statements, not whitespace like Python. You can find complete documentation here. Your code ...

View answer
What's the fastest way to mine a transaction so I can test contracts quickly?
6 votes

Patch to geth to make it mine faster. I would really like help in making this about 2x-4x faster than it is now, but it is 5x faster than stock geth: [March 9, 2016 EDIT - this new patch now mines ...

View answer
Waiting for a transaction to be confirmed
Accepted answer
5 votes

Example here using filters: How do I know when I've run out of gas programmatically? and also here by busy polling: https://github.com/barkthins/ether-pudding/blob/master/index.js#L375 I use ...

View answer
Getting segmentation fault while compiling solidity contract
5 votes

Compile it using the latest solc version at http://chriseth.github.io/browser-solidity/. If you don't get good output, then you have a bug you can file with the solidity folks. I had a segfault back ...

View answer
Best way to debug Large / Optimized contracts in Mix
Accepted answer
5 votes

At risk of being downvoted, I'll say "don't debug using a debugger". Use solidity events, and log profusely in your contracts. Logging is dirt cheap when it comes to gas, and it's easy to capture ...

View answer
Multiple transactions from same address
5 votes

If you have transaction dependencies in your off-blockchain application you should wait until the prior transaction has been mined before submitting the next transaction. Generally the process is ...

View answer
What is meant in this tutorial when it says that using throw will "consume all provided gas"?
Accepted answer
5 votes

Does this mean that, if you provide a large amount of excess Ether that it won't be refunded after a throw? Close. It means if you provide a large amount of excess GAS that the gas won't be refunded....

View answer
Check if Contract variable is undefined
3 votes

By some Solidity coding conventions you add a boolean 'valid' element to any struct to indicate it is undefined (false is the initialized value). Sometimes I see fields having zero reserved to mean ...

View answer
Geth Console - Sleep after mining a block?
3 votes

I created a geth test setup (Based on 1.3.x, haven't updated yet). It mines at much faster speeds. I think I'll add the answer above to this, I like the idea of not consuming CPU when there's ...

View answer
what is a standard .gitignore for truffle?
2 votes

The answer probably should be - you MUST check in your build directory once you've deployed, because it caches the addresses of your contracts, which is absolutely critical to the truffle deployment ...

View answer
eth.getPastLogs() requires exact match 32 byte value, how to get bignumber to emit?
2 votes

I upvoted the above answer but it will soon be out of date because web3.js in v1.0 exposes the padding functions. It's better not to reinvent the wheel. So my code looks like this: topic = '0x' + ...

View answer
Why do I get serialization errors in calling events?
2 votes

There's a workaround documented here: https://gitter.im/ethereum/web3.js/archives/2016/01/09 Change the fromBlock: 0 to fromBlock: 'latest' according to that chat. AFAICT nobody has identified a ...

View answer
How can I confirm validity of deployed contract?
2 votes

Your answer is in the web3.js documentation. rough outline: You will need: your contract's ABI and code created by solidity. call web3.eth.contract() with the ABI to create a web3.js contract ...

View answer
Retrieving historical balance and lifespan of an address
2 votes

You could keep a map of (blockchain_number + address) -> balance in your contract, and update it every time you need to interact with that address. This will use up a large amount of storage and cost ...

View answer
How to know if a transaction went through or not? (out of gas)
2 votes

If you want to determine how you've run out of gas programmatically, instead of after the fact debugging, see: How do I know when I've run out of gas programmatically?

View answer
Confused by internal transactions
1 votes

Answering this specific question: 2) Other than by clicking on EtherScan's 'Internal transactions' link, how can I possibly know about these 'internal' transactions? There's an alternate solution ...

View answer
How can I access the address of a contract created by another contract?
1 votes

Often the contract itself is going to need to store the address for future use. So just store the address in the contract as an attribute, and retrieve it from outside the contract using the usual ...

View answer
Does ethereum clients return false data if someone manipulate local blockchain data?
1 votes

geth, parity, et. al. are nodes running software that have two main interfaces - one RPC, and one to the blockchain. It's entirely possible to hack a node and lie to the RPC client. It's not ...

View answer
How to export transactions into a CSV file
1 votes

If you are writing the contract you include events in your contract to track what's happening, and then you can log those events easily to a CSV file. This will include internal transactions as well, ...

View answer
Why does web3.js throw anonymous errors and swallow errors?
1 votes

These issues are unintentional and are being fixed. https://github.com/ethereum/web3.js/issues/411 was submitted to track these issues. https://github.com/ethereum/web3.js/pull/402 fixes the first ...

View answer