# Contract Debugging
# Debugging Environment
In order to debug smart contract, you need setup a local node and do debugging through your node's RPC interface.
Vite provides 2 debugging environments: development and testing.
- Account balance is NOT verified before sending transaction.
- Each transaction can utilize maximum 47.62
UTquota with no staking.
- Quota and balance are verified normally. Pay attention to your balance and quota during debugging.
It is possible to debug your smart contract in Microsoft Visual Studio Code (aka VS Code) in development environment.
# Debugging in VS Code
Soliditypp extension for VS Code supports debugging
solidity++ smart contract in local development environment.
Following features are supported:
solidity++code auto completion
- Auto compilation when saving
- Compilation error highlighting
- Detailed error message displaying when mouse over
- One-click smart contract deployment and debugging
- Support for multiple smart contract interaction
- Deployment/debugging result displaying
- Support for offchain queries
# Install the Extension
Search for "Soliditypp" in VS Code and install.
# Create HelloWorld.solpp
Open VS Code workbench, press
F1) in Mac(or
Ctrl+Shift+P in Windows) to bring Command Palette, and then execute command
soliditypp: Generage HelloWorld.solpp. This will generate
HelloWorld.solpp under current folder as an example.
# Write Smart Contract
Write your contract in a new
.solpp file and then save it by pressing
⌘S in Mac(or
Ctrl+S in Windows). Your source file will be automatically compiled each time it is saved.
Lines with compilation error in the code will be marked with red underscore. Detailed error message will be displayed when you mouse over.
VS Code will recognize
.solpp file as
solidity++ source by default.
# Deploy/Debug Smart Contract
In Debug panel, start debugging and choose
Soliditypp environment. This will launch a local
gvite node and all following deployment and debugging steps will take place on this node.
Please note that all data will be cleared from the node after debugging is complete.
- Section 1: soliditypp source code panel
- Section 2: current address used for contract deployment and debugging. If you want to use a different address, click
+to generate a new address and then choose the address in the droplist on the right side
- Section 3: deploy panel. Field
amountcan be used to send VITE (1 VITE = 1e18 attov) upon deploying the contract. Click
deploybutton to deploy the contract in local development environment.
- Section 4: contracts deployed. Multiple results will be displayed if more than one contracts are deployed. Parameter
amountis used to send VITE to the contract when calling a function. For example, clicking
call "SayHello"will call method
- Section 5: deployment/debugging result.
Receiveshows the information of request/response transaction. New request transaction is displayed in
Receiveif it calls other method. Please note that transactions in Vite are asynchronous and user may need wait until the response transaction is generated after sending the request. More information about
Receiveplease see AccountBlock。
# Debugging in Command Line
# Development Environment
Download Gvite Debugging Package (opens new window) in development environment and install
Check gvite.log to see if gvite debugging environment has been started successfully
Following messages show a successful startup
# Create Contract
First write contract in Solidity++ and save into a ".solpp" file under the same directory with start script
Deploy contract in local debugging environment
The parameters are explained below
Following return message shows the contract has been created successfully
# Call Contract
Return message is explained below
Script call.sh shows an example how to call a contract
# Verify Execution Result
Since the response transactions of creating or calling contract are processed asynchronously, we have to wait for a while(1~6s in local environment) after sending out the request. Executing steps and results are recorded in two separate logs.
Logs are under
/ledger/devdata/vmlog in the folder unzipped
vm.log：Contains logs of contract execution entrance, result and events
interpreter.log：Contains detailed info of contract execution steps, including VM instructions, status of stack, memory, storage and etc.
It's also feasible to query contract account chain to check contract execution result
# Testing Environment
Download Gvite Debugging Package (opens new window) in testing environment and install
Installation steps in testing environment are similar as in development environment. See Install.
# Create Test Account
Remember to create new test account and stake for the account each time gvite has been rebooted. The test account will be used to create or call contract.
Following steps are finished during account creation
- Creating new test account address
- A amount of tokens are sent out from genesis account to test account
- Tokens are received by test account
- Genesis account stakes for test account to obtain quota
- Test account waits to receive quota
# Create Contract
Compared with in development environment, additional test account address should be specified when running create_contract.sh
Run pledge_for_contract.sh to stake for contract account created
# Call Contract
See Call Contract in development environment