# 2. How to Use Starknet IDE

{% embed url="<https://www.youtube.com/watch?v=31tAJcYQey0>" %}

## 1. Write a contract

After entering the project, you can click on the "preview" option at the top right corner of the readme.md file in the folder to preview it.

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2FsjwkxQTKf7g7U5HMslKe%2Fimage.png?alt=media&#x26;token=9101b1e9-104b-40b7-b7b5-308c24538566" 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%2FQ1HeZXIufYXGVDqxucfg%2Fimage.png?alt=media&#x26;token=d9e66c2f-4102-48a4-a38c-ec27f77d35ad" 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%2FJPctiJDyKByXSvCjY0fF%2Fimage.png?alt=media&#x26;token=748de1e2-5051-44df-b0d9-5458c81577ab" alt=""><figcaption></figcaption></figure>

## 2. Test a contract

Once your contract code is written, click on the "Compiler" button in the right-side menu to open the compilation module. After selecting the Module Package Path, click on "Test."

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2FyocWtStkJrdNur7eecdZ%2Fimage.png?alt=media&#x26;token=ee65c0dd-5400-427a-8345-4ac8c8a5f2ff" alt=""><figcaption></figcaption></figure>

After a successful test, the test results will be displayed in the console.

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2FH3lhcPOjqEG68x3XPNfT%2Fimage.png?alt=media&#x26;token=72584546-af6d-4d88-a4f9-5f504066602e" alt=""><figcaption></figcaption></figure>

## 3. Compile a contract

On the right-hand menu bar, under the Compiler section, click on "Build" to start compiling the contract.

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2FiEIRbL7ifQwEum6a4fgb%2Fimage.png?alt=media&#x26;token=96972427-6016-471e-abd8-6f47e2490cfd" alt=""><figcaption></figcaption></figure>

After a successful compilation, a "target" folder will be generated in the current directory.

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2FelVBt0qH1Vv5maf86Ay0%2Fimage.png?alt=media&#x26;token=e9190720-57e7-4e4d-97d5-f271626a994f" alt=""><figcaption></figcaption></figure>

## 4. Connect to Starknet

Before deploying the contract, you need to click on "Connect Wallet" in the top right corner and choose to connect either Argent X or Braavos.

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2F2xelx64tg2xCDtPecTZ5%2Fimage.png?alt=media&#x26;token=50560923-b074-47cf-8b27-50aa67c9ef7a" alt=""><figcaption></figcaption></figure>

## 5. Deploy a contract

Click on the "Deploy & Interaction" button on the right side, which will take you to the deployment and interaction page. Once there, select the compiled package and contract. After selecting the desired options, click on "Deploy" to initiate the deployment process (then confirm the transaction in your wallet).&#x20;

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2FN7U2WQO1uvR7ac3P9zyW%2Fimage.png?alt=media&#x26;token=822fc747-5632-4e38-9a81-43927e7bfc5f" alt=""><figcaption></figcaption></figure>

Deploying a smart contract in Starknet requires two steps:

* Declaring the class hash of your contract, i.e. sending your contract’s code to the network.
* Deploying a contract, i.e. creating an instance of the code you previously declared.

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2Fiopf6Ke1urgrBxVE8MZ2%2Fimage.png?alt=media&#x26;token=dc801754-cb2f-45c0-b854-b7af7654ee61" alt="" width="443"><figcaption></figcaption></figure>

Once the contract is successfully deployed, the console will output the result of the deployment along with relevant information.

If you haven't selected a contract in the "Select Compiled Contract" section, you can upload a locally compiled file for contract deployment.

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2Fh072piZ7o7jlAloDTK0Y%2Fimage.png?alt=media&#x26;token=92aafc3c-23ce-4dda-8337-0937c08c1e01" 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%2FHSN5rEguTkECxdlBsv0z%2Fimage.png?alt=media&#x26;token=c722f49e-8565-4072-af38-4457a78830c6" alt=""><figcaption></figcaption></figure>

In addition, you can also click on "Import Deployed Package" to import a previously deployed contract for contract interaction.

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2FvSiNqKz9SfScG2ovpnRN%2Fimage.png?alt=media&#x26;token=b870fbac-1183-4f5c-be1c-5d60f44abb8b" alt=""><figcaption></figcaption></figure>

You can also deploy a contract by clicking on "Use On-Chain Contract Classhash" and using a previously declared classhash for deployment.

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2FE0YvMVpYkTseL9Ffulpm%2Fimage.png?alt=media&#x26;token=68d5878d-098a-4d10-8658-4c386fcc539d" alt=""><figcaption></figcaption></figure>

## 6. Contract interaction

After a successful contract deployment, you can interact with the contract. Click on the deployed contract, choose the corresponding interface, and click on "Execute" to initiate the write interaction.

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2FZ9PUYwTvvt8aleMygzy8%2Fimage.png?alt=media&#x26;token=df4301c7-eba3-4cb2-a289-6d74f00a38b1" alt=""><figcaption></figcaption></figure>

## 7. Package & Object Query

Click on "Account Objects" and enter the corresponding fields to query the relevant information.

<figure><img src="https://3745657014-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MYy-lqJKjq1m0yBAX4r%2Fuploads%2FaHhGRJXqM1HrYtNhHAXA%2Fimage.png?alt=media&#x26;token=dd866a97-dda5-47ae-a748-131133ef02d0" alt=""><figcaption></figcaption></figure>

## 8. Starknet Sandbox

If you prefer using the command line for development, you can open the Starknet Sandbox, which comes pre-loaded with [Starkli](https://github.com/xJonathanLEI/starkli), [Scarb](https://github.com/software-mansion/scarb), [Dojo](https://github.com/dojoengine/dojo), [Starknet Foundry](https://github.com/foundry-rs/starknet-foundry)**,** [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%2Fy86OytLSvLjeNXmYQSoO%2Fimage.png?alt=media&#x26;token=f8468c17-51bf-4fc8-bce1-debd5c25aad4" 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).
