# Deploy with Thirdweb

[Thirdweb](https://thirdweb.com/) is a complete web3 development framework that offers everything you need to connect your apps or games to the Somnia network. Its service allows developers to build, manage, and analyze their Web3 applications.

This tutorial will guide you through deploying a Smart contract to the Somnia Devnet using Thirdweb’s command-line tool (\`thirdweb deploy\`). Thirdweb simplifies deployment and interaction with smart contracts on Somnia.

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

## Prerequisites

* This guide is not an introduction to Solidity Programming; you are expected to understand Basic Solidity Programming.
* To complete this guide, you will need MetaMask installed and the Somnia DevNet added to the list of Networks. If you have yet to install MetaMask, please follow this guide to Connect Your Wallet.
* Thirdweb CLI: Install globally with:

```bash
npm thirdweb install
```

## Set Up the Project

First, create a new folder for your project and initialize it.

```bash
mkdir somnia-thirdweb-example
cd somnia-thirdweb-example
```

## Write the Smart Contract

You can write your Smart Contract using the [Remix IDE](/developer/development-frameworks/deploy-with-remixide.md) to ensure it works. Create a file **`OpenGreeter.sol`** and add the following code:

<details>

<summary>OpenGreeter.sol</summary>

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

contract OpenGreeter {
    string public name;
    address public owner;

    event NameChanged(string oldName, string newName);

    constructor(string memory _initialName) {
        name = _initialName;
        owner = msg.sender;
           }

    function changeName(string memory _newName) public {
        string memory oldName = name;
        name = _newName;
        emit NameChanged(oldName, _newName);
    }

    function greet() external view returns (string memory) {
        return string(abi.encodePacked("Hello, ", name, "!"));
    }
}
```

</details>

This is a simple Greeter Smart Contract that any address can call the **`changeName`** function. The Smart Contract has two functions:\
\
\&#xNAN;**`changeName`** - This function allows anyone to change the name variable. It stores the old name, updates the name variable, and emits the **`NameChanged`** event with the old and new names.

**`greet`** - This function returns a greeting message that includes the current name. It uses abi.encodePacked to concatenate strings efficiently.

## Deploy the Smart Contract using Thirdweb.

First, go to Thirdweb and create a profile. After you have completed the onboarding process, create a Project.

<figure><img src="/files/SSIrb1BijuhrT963CKek" alt=""><figcaption></figcaption></figure>

Go to the project **settings.**

<figure><img src="/files/3ue1mXWDRIbGZKmRaC6h" alt=""><figcaption></figcaption></figure>

**C**opy your secret key, and keep it safe. The secret key will be used to deploy the Smart Contract.

<figure><img src="/files/m3XLHHHAkOfOOO0zwOGm" alt=""><figcaption></figcaption></figure>

Go to the terminal and paste the following command to deploy the Smart Contract:

```bash
npx thirdweb deploy -k your_secret_key
```

Select the **`solc`** option to be **`true`** in the prompts on Terminal.

<figure><img src="/files/JotRg5GsTH54W0YZtZbV" alt=""><figcaption></figcaption></figure>

Click the link to open the User Interface in your Browser to deploy the Smart Contract.

<figure><img src="/files/VYJoRY47ZA3jeK95Z5tS" alt=""><figcaption></figcaption></figure>

Enter an initialName. Select the Network as Somnia Devnet. Check the option to import it to the list of Contracts in your Thirdweb Dashboard. Click on **`Deploy Now`** and approve the Metamask prompts.

<div><figure><img src="/files/vqM6uzAbqNvhGqXTVXAN" alt=""><figcaption></figcaption></figure> <figure><img src="/files/jNKYorElQsAgeKXKewC9" alt=""><figcaption></figcaption></figure></div>

Your Smart Contract is deployed, and you can view it on your Thirdweb Dashboard.

<figure><img src="/files/WZCzF48XgDeBYVLVBfSF" alt=""><figcaption></figcaption></figure>

Visit the Explorer section to simulate interactions with your deployed Smart Contract and carry out actual transactions.

<figure><img src="/files/CHLsnjxtulvQ94u8ruQ5" alt=""><figcaption></figcaption></figure>

Congratulations. 🎉 You have deployed your Smart Contract to the Somnia Network using Thirdweb. 🎉

<br>


---

# 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.somnia.network/developer/development-frameworks/deploy-with-thirdweb.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.
