# Deploy using Foundry

[Foundry](https://getfoundry.sh/) is a Solidity framework for deploying smart contracts, built by [Paradigm](https://paradigm.xyz/) and written in Rust to be blazingly fast.

## Before you Begin

* Check if you are using the right [network configuration](/plume/developers/network-information.md)
* Have enough test tokens in your wallet

{% hint style="info" %}
Learn more about claiming test tokens from [here](/plume/developers/how-to-guides/how-to-connect-to-network/claim-test-tokens.md).
{% endhint %}

## Foundry Setup

Simply follow their ["Getting Started" documentation](https://book.getfoundry.sh/getting-started/installation) to install and run Foundry, then follow their ["Projects" documentation](https://book.getfoundry.sh/projects/creating-a-new-project) to create a new project.&#x20;

Run the following commands in your terminal:

```sh
curl -L https://foundry.paradigm.xyz | bash
foundryup
```

## Setup your project

To start a new project with Foundry, use [`forge init`](https://book.getfoundry.sh/reference/forge/forge-init.html):

```sh
forge init plume
```

Let's install the OpenZeppelin dependency required for our sample smart contract.

```sh
forge install openzeppelin/openzeppelin-contracts
```

<details>

<summary>Sample Smart Contract Code</summary>

This is a sample NFT contract based on [OpenZeppelin's open-source ERC-721](https://docs.openzeppelin.com/contracts/4.x/erc721) implementation to tokenize our CBO's prized Rolex watch on Plume.

{% code title="src/RolexYachtMaster40.sol" %}

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract RolexYachtMaster40 is Ownable, ERC721 {
    error NFTAlreadyMinted();
    bool private _minted;

    constructor() Ownable(msg.sender) ERC721("Rolex Yacht-Master 40", "") {}

    function mint() public onlyOwner returns (uint256) {
        if (_minted) {
            revert NFTAlreadyMinted();
        }
        _safeMint(owner(), 0);
        _minted = true;
        return 0;
    }
}
```

{% endcode %}

</details>

Then, compile the project using [`forge build`](https://book.getfoundry.sh/reference/forge/forge-build.html):

<pre class="language-sh"><code class="lang-sh"><strong>forge build
</strong>
[⠰] Compiling...
[⠔] Compiling 38 files with Solc 0.8.27
[⠒] Solc 0.8.27 finished in 1.01s
Compiler run successful!
</code></pre>

## Deploy your Contract

Follow the instructions on in the ["Deploying" documentation](https://book.getfoundry.sh/forge/deploying) and set your `PLUME_RPC_URL` environment variable similar to the ETH RPC URL. The below command will deploy the sample smart contract provided above on **Plume Testnet** for instance (switch the RPC and verifier URL to Mainnet to deploy on Plume Mainnet).

{% code overflow="wrap" %}

```sh
export PLUME_RPC_URL=https://testnet-rpc.plume.org
export CONTRACT_PATH=<contract_file>:<contract_name>

forge create $CONTRACT_PATH \
    --rpc-url $PLUME_RPC_URL \
    --broadcast \
    --legacy --interactive
```

{% endcode %}

{% hint style="info" %}
To verify the contract while deploying, use `--verify`  flag, more details [here](https://book.getfoundry.sh/forge/deploying).
{% endhint %}

The below command will verify the contract and deploy it simultaneously.

```sh
export PLUME_RPC_URL=https://testnet-rpc.plume.org
export VERIFIER_URL=https://testnet-explorer.plume.org/api/
export CONTRACT_PATH=<contract_file>:<contract_name>

forge create $CONTRACT_PATH \
    --rpc-url $PLUME_RPC_URL \
    --verify \
    --verifier blockscout \
    --verifier-url $VERIFIER_URL \
    --broadcast \
    --legacy --interactive
```

{% hint style="warning" %}
Make sure to replace the details in the `<contract_file>:<contract_name>` with your contract details.
{% endhint %}

### Sample Output

```sh
No files changed, compilation skipped
Enter private key:
Deployer: 0x32820DE739394C1ee69264ef3C0193E4B5C0122c
Deployed to: 0xa43a88ccfec87295aa0c5017a7ddcc5cdfcacdd0
Transaction hash: 0x1441297a9288fc37820a09e2e9b1d14d62b5d6341fd1e14159eabcedb7dfe115
```

You can view the deployed contract on the [Plume Testnet Explorer](https://testnet-explorer.plumenetwork.xyz/).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.plume.org/plume/developers/how-to-guides/how-to-deploy-smart-contracts/deploy-using-foundry.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
