The ultimate goal of this tutorial is to debug transactions that have
been created by a dapp front end.

It is easy in Remix to debug a transaction created from its own GUI.
However, setting up an environment that allows you to debug transactions
created outside of Remix, require a bit more of complexity.

We will need four tools for that :

Geth - this is the center piece and provides the blockchain
environment. We will basically run geth in a dev mode.

Mist - this is the Ethereum dapp browser. We will use it to browse
our front end.

Remix - this is the Ethereum IDE. We will use it to develop our
Solidity contract.

<test-chain-directory> is the folder where keys and chain data will be
stored.

--ipcpath defines the end point that other apps (like Mist) use to
talk to geth.

--datadir specifies the data directory.

--dev sets the node into private chain mode and adds some debugging
flags.

Then we need to create accounts and mine a bit to generate some Ether:

// from the geth console :personal.newAccount()// You can execute this command several time if you need more than one account.miner.start()// generate some Ether.miner.stop()// stop mining after 30s-60s - we could also keep mining.

Next time we run Geth, we will only need to mine transactions (no need
to recreate account).

If we run Mist without any argument, its internal Geth node will run. As
we have our own we need to specify the ipc path of the node installed
above.

mist --rpc <test-chain-directory>/geth.ipc

(yes the option is –rpc)

Once Mist is started, verify that it is connected to the test node
(that’s very important!!).

On the bottom left, check that the network is Private-net and that the
block number is the same as reported by the test node we are currently
running. Run the following command in the Geth Console to check:
web3.eth.blockNumber.

Clicking on Wallet will allow you to send transactions and check account
balances (if you are currently mining you should see the balance
increasing).

The variable contractspec contains the abi of the donation contract.
This means that if you change something in the contract interface
(function names, parameters, …) you need to copy the new abi from
remix to the front end.

This creates a new transaction that deploys the Donation contract
(Mist will ask for the usual passphrase check).

Wait for the transaction to be mined (don’t forget to activate mining
miner.start()). Once this is done, you can use it by executing the
moveFund and donate function. But this is not what we want to
achieve. We want to run and debug those functions from the front end.

Remix also display the address of the contract. Save it, we’ll need this
address later.

From Mist, browse the above front end. In the first field, paste the
address of the newly created contract. Now, let’s call the first
function (label give).

You will need an account and a value.

The account could be any account that is declared in the Wallet section
of Mist. This is the sender of the transaction that we are going to
create. The value should be no more than the actual balance of the
account - the unit is in wei, so just put 100 (100 wei), that should
be fine.

Click on Give and wait for the transaction to be mined.

The HTML block with id log is filled by all the transactions created
from the front end. It was easier for the purpose of this tutorial to
just log transactions in a div but you can have your own logging
mechanism.

There is only one field that we need, this is the transactionHash.

Copy it and switch to Remix. On the right side, the fifth panel shows a
small “bug” icon, that is the debugger.

Paste the hash into the transaction field and click on the play
button.

You are now entering a debug session for the call to donate.

Debugging in Remix is easier than with common tools like gdb because you
can freely move in time. Use the slider to change the current step and
click on the panels below to expand them and explore the curret state,
local variables, etc. There are also breakpoints to move between
sections of the code quickly, but more on all that later.