How to do it...

  1. Access Remix by navigating to https://remix.ethereum.org/.

  1. Let's use the following smart contract to test the debugging functionality. The contract uses a function to set the value of state variables and doesn't do anything complex:
pragma solidity^0.4.24;

contract Sample {
uint value;
address sender;

function setValue(uint _value) public {
value = _value;
sender = msg.sender;
}
}
  1. Navigate to the Run tab in the right panel and click Deploy to deploy the contract. Be sure to set the Environment as JavaScript VM. It will deploy the contract to a built-in Ethereum instance and will generate an interface to interact with the contract in the right panel, as shown in the following screenshot:

  1. You can access the debugger by navigating to the Debugger tab in the right panel. It allows you to specify a transaction hash or a block with a transaction index to start the debugging process, as shown in the following screenshot:

  1. The debugger gives you the option to navigate the code by each instruction. You can also read the current state of the machine from the debug window. This window provides options to read the instructions, local states, step details, values in the stack, values in memory, call data, call stack, and more.

  2. Let's try to make a transaction and debug it. Use the Deployed contract section under the Run tab to call the setValue function. Once the transaction is sent, you can see the status of the transaction on the bottom console. You will also be given an option to debug the transaction.

  3. Click the Debug button to start the debugging process for the specified transaction.

  1. Navigate through the instructions by moving the slider or by clicking the buttons right below it. The debugger will highlight the code that represents the current instructions in the editor window. You can also see the values of states being changed for each instruction, as shown in the following screenshot:

  1. You can stop the debugger at any point by clicking the stop icon in the debugger window.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.9.169