Verona 백서

Verona

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 54쪽 중 23쪽

ows/wsl/tutorials/wsl-vscode), which includes installing the [Remote Development extension pack](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack). This extension enables you to run WSL, SSH, or a development container for editing and debugging with the full set of Visual Studio Code features. Quickly swap between different, separate development environments and make updates without worrying about impacting your local machine. Once VS Code is installed and set up, you can open your WSL project with a VS Code remote server by entering: `code .` . *Be sure to add the period at the end of the command to open the current directory.* ![VS Code with WSL extensions displayed](https://learn.microsoft.com/en-us/windows/wsl/media/vscode-remote-wsl-extensions.png) ## Optimize Contract: Example In this example, we’ll walk through the steps to compile a Verona smart contract using the setup described above. ### **Clone the Repository** <a href="#clone-the-repository" id="clone-the-repository"></a> Start the **Ubuntu** app, and in the terminal, use the following commands to clone the repository and navigate into the project directory: ```sh git clone https://github.com/burnt-labs/cw-counter cd cw-counter ``` {% hint style="info" %} Make sure Docker is running. {% endhint %} Next, compile and optimize the smart contract using the [CosmWasm Optimizing Compiler](https://github.com/CosmWasm/optimizer). You need to have **Docker** running to execute the command below: ```sh docker run --rm -v "$(pwd)":/code \ --mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \ --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ cosmwasm/optimizer:0.16.0 ``` Once compiled, the optimized contract will be available at: ```sh ./artifacts/cw_counter.wasm ``` ### Using Visual Studio Code To optimize the contract from within **Visual Studio Code**, open your project using the command: ```sh code . ``` This will launch the project in Visual Studio Code. From there, open a terminal within the IDE and run the Docker command above. ## Install `xiond` Binary You can now follow this [guide](/en/build-on-verona/computation/local-development/setting-up-env/installation-prerequisites-setup-local-environment#xiond) to install `xiond` within the Ubuntu environment. It's preferable to use the **Debian based** installer. # Set Up an Integrated Development Environment (IDE) Integrated Development Environment Setup for Verona Network Smart Contract Development A well configured Integrated Development Environment (IDE) can significantly streamline your smart contract development. While there are many options available for Rust development, the following IDEs stand out as top choices: * [**Visual Studio Code (VS Code)**](https://code.visualstudio.com/docs/languages/rust) – Provides the best overall experience with strong Rust support (Recommended). * [**RustRover**](https://jetbrains.com/rust/) – A JetBrains IDE tailored specifically for Rust development, offering deep integration with Cargo, advanced debugging, and robust code navigation. * [**Eclipse**](https://projects.eclipse.org/projects/tools.corrosion) – A versatile IDE with Rust support through plugins like RustDT, suitable for developers who prefer an extensible and customizable environment. Among these, we recommend **VS Code** for its excellent Rust support, ease of configuration, and built-in frontend development capabilities, eliminating the need for multiple tools. ## Prerequisites * Before proceeding, ensure that the **Rust compiler (rustc)** is installed. You can refer to the [Installation Guide](/en/build-on-verona/computation/local-development/setting-up-env/installation-prerequisites-setup-local-environment#rust) for step-by-step instructions on setting up Rust before continuing. ## Install Visual Studio Code (**VS Code)** **VS Code** is a widely used, free, and open-source IDE known for its powerful features, including a rich code editor, built-in Git integration, and robust debugging tools. With an extensive marketplace of extensions, VS Code provides excellent support for various programming languages, including **Rust, Go, C++, Java, Python, and more**. It is available on **Windows, macOS,** and **Linux**. Follow the steps below to install VS Code on your operating system: {% tabs %} {% tab title="Linux" %} See the [Download Visual Studio Code](https://code.visualstudio.com/download) page for a complete list of available installation options. To install via the terminal use one of the following methods based on your operating system: * **Debian/Ubuntu** (via `.deb` package): ```sh sudo apt install ./<file>.deb # Replace <file> with the downloaded .deb file ``` * **Fedora/RHEL** (via `.rpm` package): ```sh sudo rpm -i <file>.rpm # Replace <file> with the downloaded .rpm file ``` * **Snap (Universal Linux Install)**: ```sh sudo snap install --classic code ``` {% endtab %} {% tab title="macOS" %} 1. Download the macOS version from the [VS Code website](https://code.visualstudio.com/). 2. Open the downloaded `.zip` file and move the **Visual Studio Code** app to the Applications folder. 3. (Optional) Install the **Command Line Tools** by running: ```sh sudo ln -s /Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code /usr/local/bin/code ``` This allows you to open VS Code from the terminal using the `code` command. {% endtab %} {% endtabs %} ## Configuring VS Code for Rust Development To enable Rust support in VS Code you need to install the following extensions: * **rust-analyzer**: Provides syntax highlighting, code completion, error checking, and inline documentation. * **CodeLLDB**: Enables debugging capabilities for Rust and other compiled languages. ### **Installing rust-analyzer** Follow these steps to install the extension: 1. Go to the **Extension** panel 2. In the **Search** field enter **rust-analyzer** 3. Click the **install** button to the bottom right of **rust-analyzer** <figure><img src="https://3630978198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FB5Z5ijJgMx0GJO3l1Il9%2Fuploads%2Fldr6UOGi7icZsRx3ljPz%2Fimage.png?alt=media&amp;token=75922838-b885-4ac1-913a-44a73bf788e7" alt=""><figcaption></figcaption></figure> ### **Installing CodeLLDB** The **CodeLLDB** extension is a native debugger essential for debugging Rust applications. Follow these installation steps: 1. Open VS Code and navigate to the **Extensions** panel. 2. Search for **CodeLLDB**. 3. Click the **Install** button next to **CodeLLDB**. For comprehensive usage details, refer to the [CodeLLDB Manual](https://github.com/vadimcn/vscode-lldb). <figure><img src="https://3630978198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FB5Z5ijJgMx0GJO3l1Il9%2Fuploads%2FmQMbg7JwkLftl3ofvPn9%2Fimage.png?alt=media&amp;token=a4743be5-7b06-4a74-bb40-0d9e92a294a0" alt=""><figcaption></figcaption></figure> ### Cosmy wasmy <a href="#cosmy-wasmy" id="cosmy-wasmy"></a> [Cosmy Wasmy](https://marketplace.visualstudio.com/items?itemName=spoorthi.cosmy-wasmy) is a VS Code plugin designed to streamline the development and interaction with CosmWasm smart contracts. It comes pre-configured with popular CosmWasm testnets, making chain interactions seamless during testing. With Cosmy Wasmy, you can manage all interactions directly within VS Code, eliminating the need for the CLI. For details on installation, configuration, and available commands and features, explore [Cosmy Wasmy](https://marketplace.visualstudio.com/items?itemName=spoorthi.cosmy-wasmy). # Deploying Your First Smart Contract This guide will walk you through the process of deploying a smart contract on the **Verona** network. The deployment process involves **compiling** an **optimized** version of your contract code, **uploading** this optimized code to the blockchain, and then creating an **instance** of the contract. Once instantiated, the contract will have its own **unique address** and **data store**, allowing you to interact with it through transactions and queries. ## Prerequisites Before deploying your smart contract on-chain, ensure you have completed the following setup steps: * **Set up your local environment**: Follow the [installation and setup guide](/en/build-on-verona/computation/local-development/setting-up-env/installation-prerequisites-setup-local-environment) to configure your development environment. * **Install the Verona daemon (`xiond`)**: Set up the `xiond` CLI by following the [installation instructions](/en/build-on-verona/tools/daemon-cli) to interact with the blockchain. * Make sure you have [Docker](https://www.docker.com/get-started) installed and running, as it is required to compile your contract. ## Generate an account To execute transactions on-chain, you need at least one funded account. This section will guide you through the process of creating and funding an account using `xiond`. ### Generate an Account Key Pair To interact with the Verona network, you need a cryptographic key pair, consisting of a **public key** and a **private key**. The public key is used to derive your address, while the private key is required to sign transactions. #### **Generate a New Key Pair** Use the following command to create a new key pair and add it to your local key store: ```sh xiond keys add <keyname> ``` Replace `<keyname>` with a name of your choice for easy reference. #### **Retrieve Public Key** If you have already generated a key pair and need to retrieve its public key, use the following command: ```sh xiond keys show <keyname> ``` Replace `<keyname>` with the name of your key to display its public key. ### Fund Your Account Your account is not fully registered on-chain until it is involved in a transaction. The easiest way to achieve this is by **funding your account**, which allows it to interact with the network. #### **Request Testnet Tokens** You can obtain testnet tokens from the [Verona Faucet](https://faucet.xion.burnt.com). Follow the instructions on the site to receive testnet tokens. For more details on accessing testnet tokens, see our [Faucet Page](/en/build-on-verona/references/testnet-tokens). #### **Mainnet Tokens** If you’re deploying contracts on **Verona Mainnet**, you can acquire $VERONA tokens through various **decentralized** and **centralized exchanges**. ## **Compile and Optimize the Contract** {% hint style="warning" %} WASM built with the **latest stable Rust** may fail to **store** on Verona because bulk memory is not supported. If upload fails after a Rust upgrade, create `rust-toolchain.toml` at the contract project root and pin **1.86** (latest stable known to avoid bulk memory for `wasm32-unknown-unknown` as of May 2026; re-test when upgrading Rust or when Verona enables bulk memory): ```toml [toolchain] channel = "1.86" targets = ["wasm32-unknown-unknown"] ``` Then rebuild and re-run the optimizer below before `xiond tx wasm store`. {% endhint %} To demonstrate the deployment process, we’ll use a simple [**Counter**](https://github.com/burnt-labs/cw-counter) smart contract. This contract provides an example of state management on the Verona network. It allows you to: * Set an initial counter value * Increment or reset the counter * Query the current counter value ### **Clone the Repository** First, you need to download the contract code that will be compiled. Use the following commands to clone the repository and navigate into the project directory: ``` git clone https://github.com/burnt-labs/cw-counter cd cw-counter ``` ### **Optimize Contract** Next, compile and optimize the smart contract using the [CosmWasm Optimizing Compiler](https://github.com/CosmWasm/optimizer). You need to have **Docker** running to execute the command below: ``` docker run --rm -v "$(pwd)":/code \ --mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \ --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ cosmwasm/optimizer:0.16.1 ``` #### **Why Optimization is Important** Optimization ensures that the contract is compiled into a compact **WebAssembly (WASM) binary**, reducing on-chain storage costs and improving execution performance. Once compiled, the optimized contract will be available at ``` ./artifacts/cw_counter.wasm ``` ## **Upload Optimized Contract On-chain** First, set your wallet address or key name by executing the following in your terminal: ``` WALLET="your-wallet-address-or-key-name-here" ``` Now, upload the contract to the blockchain: ``` RES=$(xiond tx wasm store ./artifacts/cw_counter.wasm \ --chain-id xion-testnet-2 \ --gas-adjustment 1.3 \ --gas-prices 0.001uxion \ --gas auto \ -y --output json \ --node https://rpc.xion-testnet-2.burnt.com:443 \ --from $WALLET) ``` After running the command, **extract the transaction hash** by executing: ``` echo $RES ``` Example output: ``` { "height": "0", "txhash": "B557242F3BBF2E68D228EBF6A792C3C617C8C8C984440405A578FBBB8A385035", ... } ``` Copy the **txhash** value for the next step. ## **Retrieve the Code ID** The **Code ID** is required for creating an instance of your contract. Set your **transaction hash** you retrieved above by executing: ``` TXHASH="your-txhash-here" ``` Query the blockchain to get the **Code ID**: ``` CODE_ID=$(xiond query tx $TXHASH \ --node https://rpc.xion-testnet-2.burnt.com:443 \ --output json | jq -r '.events[-1].attributes[1].value') ``` Now, display the retrieved **Code ID**: ``` echo $CODE_ID ``` Example output: ``` 1213 ``` ## **Instantiate the Contract** When you uploaded the **WASM bytecode**, you stored the **contract code** on the blockchain, but no contract instance was created yet. The uploaded code can be used to create multiple contract instances, each with its own state. Each contract instance requires a **unique initialization message** based on its expected parameters. In the case of the [**Counter** contract](https://github.com/burnt-labs/cw-counter/blob/main/src/msg.rs#L4-L6), the only required variable is `count`, which is of type `i32` (a 32-bit integer). Set the contract's initialization message by executing: ``` MSG='{ "count": 1 }' ``` Instantiate the contract with the **Code ID** from the previous step: ``` xiond tx wasm instantiate $CODE_ID "$MSG" \ --from $WALLET \ --label "cw-counter" \ --gas-prices 0.025uxion \ --gas auto \ --gas-adjustment 1.3 \ -y --no-admin \ --chain-id xion-testnet-2 \ --node https://rpc.xion-testnet-2.burnt.com:443 ``` Example output: ``` gas estimate: 217976 code: 0 txhash: 09D48FE11BE8D8BD4FCE11D236D80D180E7ED7707186B1659F5BADC4EC116F30 ``` Copy the new transaction hash for the next step. ## **Retrieve the Contract Address** Once a contract instance is created, it is assigned a **unique contract address** and its own **data store**, which can be queried for state changes and interactions. Set the new transaction hash from the contract instantiation step: ``` TXHASH="your-txhash-here" ``` Query the blockchain to get the **contract address**: ``` CONTRACT=$(xiond query tx $TXHASH \ --node https://rpc.xion-testnet-2.burnt.com:443 \ --output json | jq -r '.events[] | select(.type == "instantiate") | .attributes[] | select(.key == "_contract_address") | .value') ``` Display the contract address: ``` echo $CONTRACT ``` Example output: ``` xion1v6476wrjmw8fhsh20rl4h6jadeh5sdvlhrt8jyk2szrl3pdj4musyxj6gl ``` ## Querying the Contract The deployed contract includes a method to query the **current count value**. You can use this to retrieve the stored state. To fetch the current count, use the following: ```sh QUERY='{"get_count":{}}' ``` Run the following command to send the query request to the contract: ```sh xiond query wasm contract-state smart $CONTRACT "$QUERY" --output json --node https://rpc.xion-testnet-2.burnt.com:443 ``` This command will return the **current count value** stored in the contract. ## Execute Transactions Now that the contract is deployed, let’s interact with it by executing transactions. The contract supports two transaction types: 1. **Increment the count** → Increases the counter by **+1** 2. **Reset the count** → Sets the counter to a specified value Since these transactions modify the contract’s internal state, **gas fees** are required for execution. ### **Increment the Contract’s Count** Let’s send a transaction to **increase the count by 1**: ```sh TRY_INCREMENT='{"increment": {}}' xiond tx wasm execute $CONTRACT "$TRY_INCREMENT" \ --from $WALLET \ --gas-prices 0.025uxion \ --gas auto \ --gas-adjustment 1.3 \ -y \ --node https://rpc.xion-testnet-2.burnt.com:443 \ --chain-id xion-testnet-2 ``` After executing this transaction, you can run the **get\_count query** again to verify that the count has increased by **+1** from its previous value. ### **Reset the Contract’s Count** Now, let’s send a transaction to **reset the count** to a specific value (e.g., `0`): ```sh RESET='{"reset": {"count": 0}}' xiond tx wasm execute $CONTRACT "$RESET" \ --from $WALLET \ --gas-prices 0.025uxion \ --gas auto \ --gas-adjustment 1.3 \ -y \ --node https://rpc.xion-testnet-2.burnt.com:443 \ --chain-id xion-testnet-2 ``` Like the increment transaction, the **reset transaction** also modifies the contract’s state and requires gas fees. After querying the contract again you will confirm that the count has been reset to **0** or the value you specified. # Re-using Existing Contracts Leveraging existing, **battle-tested** smart contracts can significantly accelerate development, reduce costs, and improve security. This section highlights a curated list of pre-built CosmWasm contracts that can be deployed out-of-the-box or integrated as modules within your custom smart contracts. To ensure a secure and streamlined path to Mainnet approval, developers are strongly encouraged to adopt audited, widely used contracts where possible. Rather than building from scratch, using trusted components as building blocks minimizes risk, cuts audit expenses, and increases the likelihood of passing governance reviews. ## **Why Choose Audited & Proven Contracts?** ### **Security & Reliability** Audited contracts offer vetted security, having undergone expert review to uncover and fix vulnerabilities. Battle-tested contracts offer proven reliability, having been extensively used and validated by the community over time. A prime example is the [**cw-plus**](https://github.com/CosmWasm/cw-plus) collection of contracts. The cw-plus repository continues to serve as a valuable reference point, directing developers to these essential, community-proven contract implementations. ### **Lower Costs & Faster Time to Market** Pre-audited contracts drastically reduce audit scope and cost, as much of the core logic has already been verified. This accelerates the approval process for Mainnet deployment, where proven security is a major factor. Additionally, these contracts provide production-ready functionality, allowing developers to focus on building differentiated features rather than reinventing the wheel. The `cw-plus` suite illustrates this perfectly, offering well-maintained, standardized modules refined through extensive adoption. ## Building for Mainnet We have also put together guides on how to [**Build to get your Apps on Mainnet**](/en/build-on-verona/building-for-production). This section outlines the key differences between **Testnet** and **Mainnet**, the requirements for deployment, and best practices to ensure your contracts are approved and adopted by the community. We recommend reading through the contents of this section. # Deployed Contracts Verona provides a growing library of contracts that are already deployed and available on both **Mainnet** and **Testnet**. This makes it easy for developers to instantiate existin
프로젝트로 돌아가기