# 2. How to Use XDC IDE

## 1. Write a contract

Upon entering the project, the README.md file included in the folder will be automatically previewed.

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2FFpFgr9YSK7KEWdr25rWj%2Fimage.png?alt=media&#x26;token=dbc68331-4462-4d58-91d5-b0dc022424c1" alt=""><figcaption></figcaption></figure>

In the Explorer panel, you can create new files (or folders), refresh the directory, and download files. You can also directly click on the files that come with the template.

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2FE2cSwSZdbKLZK5YN7XGK%2Fimage.png?alt=media&#x26;token=47ea9493-d238-474e-ab62-17a9d1f83dd3" alt=""><figcaption></figcaption></figure>

Click on a contract file to edit the code.

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2Fc3NCif0cmQb6idg1jY4z%2Fimage.png?alt=media&#x26;token=a3bfae68-88a5-480d-b296-de50afd1b019" alt=""><figcaption></figcaption></figure>

## 2. Compile a contract

Once your contract code is written, click on the "Compiler" button in the right-side menu to open the compilation module. Choose the compiler version and decide whether to enable optimization, then click "Compile \*\*\*.sol" to initiate the compilation.

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2FkXoYvUeQqoCuDWHiMeKV%2Fimage.png?alt=media&#x26;token=aaa61e97-138b-4201-aee8-9252ee5d894f" alt=""><figcaption></figcaption></figure>

After successful compilation, the [ABI](https://docs.soliditylang.org/en/latest/abi-spec.html) and BYTE CODE will be displayed below, and you'll see a message in the console stating "Compile contract success."

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2FczE48oDmrmEi2hNWpGds%2Fimage.png?alt=media&#x26;token=3f51d9b4-063e-48dd-a60e-b13b54bc0781" alt="" width="326"><figcaption></figcaption></figure>

## 3. Connect to XDC

Before deploying a contract, you need to click on "Connect Wallet" in the upper right corner and select to connect to JavaScript VM (used for testing, implemented in JavaScript) or Metamask or XDCPay (for deployment on the XDC blockchain).

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2FLRhasXHh6XnfX6AsxOko%2Fimage.png?alt=media&#x26;token=81c389b6-c8b0-43c2-a26e-7f5ee01d60c9" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2FJP62rOjizBc3Pl6iBCS0%2Fimage.png?alt=media&#x26;token=6b74db34-8250-4f18-8007-728b6edde629" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2FF1iRGGxr8g0Xdgm277Sv%2Fimage.png?alt=media&#x26;token=c37155f5-dfae-4819-b3f2-bb390757534e" alt=""><figcaption></figcaption></figure>

## 4. Deploy a contract

Click the "Deploy & Interaction" button on the right-hand side, which will bring up the deployment and interaction pages. Select the compiled contract and click "Deploy" to initiate the deployment (then confirm in Metamask or XDCPay). After successful contract deployment, the console will display the contract deployment result and relevant information.

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2F5psvqSxWRHpMHVY7IcZx%2Fimage.png?alt=media&#x26;token=c7a1c6aa-8d4d-4cf5-bbbc-4ad540d16cd5" alt=""><figcaption></figcaption></figure>

In addition, you can click "Import Deployed Contract" to import a contract that has already been deployed for contract interactions.

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2Fngi6YbBoBm6q3vNHRk0s%2Fimage.png?alt=media&#x26;token=ece226e3-dcb8-46ff-bfa9-19e0dd84fddd" alt=""><figcaption></figcaption></figure>

## 5. Contract interaction

After a successful contract deployment, you can interact with the contract. Click on the deployed contract, choose the corresponding interface, and click "Submit" or "Get" to perform interactions.

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2FYvd6K7dJf2rmJgM0sBfu%2Fimage.png?alt=media&#x26;token=ba7c4ca6-d5cd-4d30-8c0c-842f009584ab" alt=""><figcaption></figcaption></figure>

## 6. Transaction Query

Click on the transaction hash in the Output section to view the specific details of each transaction.

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2FvQMnf74KsG8KIz9i1xwS%2Fimage.png?alt=media&#x26;token=05bc886d-2bf1-4c29-b98b-f7e58839231d" alt=""><figcaption></figcaption></figure>

## 7. Verify the Contract

If you wish to open-source your smart contract on a blockchain explorer, please refer to [ChainIDE Flattener](https://chainide.gitbook.io/chainide-english-1/chainide-modules/4.7-plug-in-system-module/2.7.2.-chainide-flattener-plugin).

## 8. XDC Sandbox

If you prefer using the command line for development, you can open the XDC EVM Sandbox, which comes pre-loaded with [Hardhat](https://hardhat.org/), [Truffle](https://trufflesuite.com/), [Brownie](https://eth-brownie.readthedocs.io/en/stable/), [Ganache](https://trufflesuite.com/ganache/), [Git](https://git-scm.com/) and [Node.js V16](https://nodejs.org/en).

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2FZ6ESp9vsyiLsDl5KxZDb%2Fimage.png?alt=media&#x26;token=1b7ca7c7-f806-4f88-9a49-3a7f0a6583ab" alt=""><figcaption></figcaption></figure>

If you've started a process on a port in the Sandbox and wish to access that port, please refer to [ChainIDE - Port Forwarding](https://chainide.gitbook.io/chainide-english-1/port-forwarding).
