---
description: >-
  The process of writing, compiling, deploying, interacting, verifying, and
  querying with smart contracts
---

# 2. How to use Polygon 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%2FRaVwv6APq5ETE4pU2dKw%2Fimage.png?alt=media&#x26;token=3c9515f4-8f7b-4e09-afc4-252833b67e53" 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%2FSW2imC8fZiDFNAfwpshP%2Fimage.png?alt=media&#x26;token=beb04399-2c09-4978-92c6-976fd38f3f91" 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 Polygon

Before deploying the 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 (for deployment on the Polygon 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%2F0vG3GQ9DhTu59lZheSyX%2Fimage.png?alt=media&#x26;token=a4c59e67-b6a8-4082-afdb-dd564de21499" 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%2Ft0Bz7IHIuWpBdFFR0fgv%2Fimage.png?alt=media&#x26;token=d7675497-b91b-4959-b629-6a3800f79903" 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). 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%2Fk7PQY7OuB26ORjcLb7aP%2Fimage.png?alt=media&#x26;token=75adcf4c-2c35-48ff-b869-16142e52b6bf" 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%2Fn4thIGrL2Qhxz5ogJVX0%2Fimage.png?alt=media&#x26;token=82f3a533-bd23-4179-8a2b-7e54bd14262b" 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%2FVknHLfYuASBCHmAwdOnq%2Fimage.png?alt=media&#x26;token=ffbb206b-8f0b-4b26-b730-45084b83bcee" 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%2F7iAQP9ImS5xLUmTniJdD%2Fimage.png?alt=media&#x26;token=d1da71ac-05c6-4b97-8d86-a6b644a9ea5b" 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 Verifier](../../chainide-modules/4.7-plug-in-system-module/2.7.3.-chainide-scan-verifier) or [ChainIDE Flattener](../../chainide-modules/4.7-plug-in-system-module/2.7.2.-chainide-flattener-plugin).

## 8. Polygon Sandbox

If you prefer using the command line for development, you can open the Polygon 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%2Ffvxj47eAopLNGP2DIb81%2Fimage.png?alt=media&#x26;token=0487112f-01e7-42b7-9d47-4b0097a10e6f" 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](../../port-forwarding).
