Skip to content

Commit

Permalink
Updated a number of prompts (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
emperorjm authored Oct 9, 2024
1 parent d986848 commit 7e11ca8
Showing 1 changed file with 47 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ parentSectionPath: /developers

# Overview

In this tutorial, you'll learn how to create a Lottery smart contract using the Archway Developer CLI but assisted by ChatGPT. The AI will guide you through the entire process, from setting up your project to deploying and interacting with your contract on the Archway blockchain.
In this tutorial, you'll learn how to create a **Lottery** smart contract using the Archway Developer CLI but assisted by ChatGPT. The AI will generate all the code necessary to have a fully functional contract.

Please make sure you've gone through the following [guide](/developers/getting-started/install) to install all the tools required for developing on Archway.
Please make sure you've gone through the following [guide](/developers/getting-started/install) to install all the tools required for developing on Archway especially the section of the guide to install the [Archway Developer CLI](/developers/getting-started/install#archway-developer-cli).

The following are the requirements for the lottery contract:
The following are the requirements for the `lottery` contract:

- An account enters the lottery by paying a small fee
- A winner is selected using a non-random solution
Expand All @@ -27,7 +27,24 @@ To successfully create and deploy the Lottery smart contract using the Archway D
- Ask for Clarification: If any part of the response is unclear, ask for further clarification.
- Check Outputs: After running commands, check the outputs and return any errors or messages to ChatGPT for further assistance.

Here's a step-by-step guide on what to expect and how to interact effectively with ChatGPT AI:
## Create a blank smart contract

For this project, we’ll be utilizing the [Archway Developer CLI](/developers/developer-tools/developer-cli).

The Developer CLI follows a specific structure and configuration, so we need to begin by creating a blank smart contract as the foundation for our dapp. Once your environment is ready, refer to this [setup guide](/developers/getting-started/setup#creating-a-blank-project) to generate a blank smart contract project.

## Building the smmart contract: working with key files

Now that we’ve set up the foundation of our project, it's time to begin working on the key files that will make up the smart contract. Each file plays a critical role in defining how the contract operates, manages data, and allows for user interactions. We’ll go through each file step by step, focusing on how they contribute to the overall functionality of the contract.

The main files we’ll be working on include:

- **`state.rs`**: Manages the contract’s state and data storage.
- **`msg.rs`**: Defines the messages and parameters that users can send to interact with the contract.
- **`contract.rs`**: Contains the core logic and execution flow of the smart contract.
- **`error.rs`**: Handles error management and reporting in the contract.

In each section, we will walk through what needs to be done in the file, providing guidance and instructions for building out the voting smart contract and the prompts that will be submited to `ChatGPT` for it to generate the necessary code.


## Archway custom GPT
Expand All @@ -41,7 +58,7 @@ You want to give ChatGPT an overview of what is to be built along with the requi
The first step would be to create a new project. We recommend utilizing the Archway Developer CLI for managing your project. When starting a new project that is not baed on a fleshed out template the recommendation is to start with a blank template. Currently there is no set blank template but if you utilize the `Increment` template and selecting the `minimal` option, a blank contracy will be created. The following will therefore be the first prompt:

```
I want to build a Lottery smart contract on the Archway blockchain using the Archway Developer CLI. The contract should allow users to enter the lottery by paying a small fee, and a winner is selected to end the lottery who will receive the total collected fees. The winner selection will be deterministic, based on the block height, as randomness is not supported in CosmWasm smart contracts.
I want to build a Lottery smart contract on the Archway blockchain. The contract should allow users to enter the lottery by paying a small fee, and a winner is selected to end the lottery who will receive the total collected fees. The winner selection will be deterministic, based on the block height, as randomness is not supported in CosmWasm smart contracts.
Can you guide me through the process step-by-step, starting with creating a new project and including all necessary files and commands?
Expand All @@ -54,52 +71,49 @@ The response should guide you with the commands and selections required for crea

In a CosmWasm smart contract project, the `state.rs` file is typically used to define and manage the data structures that represent the state of the smart contract. This includes defining the types and their serialization for storage, as well as the methods for interacting with the state.

Execute the following prompt:


> Generate the required data structures in the `state.rs` file for a lottery smart contract that should allow users to enter the lottery by paying a small fee, and a winner is selected to end the lottery who will receive the total collected fees. The winner selection will be deterministic, based on the block height, as randomness is not supported in CosmWasm smart contracts.
> Please ensure that the structures are serializable using `serde` and ready to be stored with `cw-storage-plus`.
> Also include comments explaining the purpose of each data structure.
## Contract logic

The main entry point for defining the core logic of the smart contract is stored in the `contract.rs` file. This file typically contains the primary functions that handle the execution of the contract's actions and queries. It orchestrates how the contract processes messages, manages state, and interacts with other contracts.


The following would be the prompt:

```
How do I create the state.rs file to define the contract's state making sure to use the latest storage features?
```
> Generate the `contract.rs` file for the lottery smart contract.
> Please make sure to include a method for initializing the contract.
> Use CosmWasm's standard response and error handling patterns, ensuring that each function interacts with the state using the structures defined in `state.rs`.
## Create messages

In an Archway smart contract project, the `msg.rs` file is typically used to define the `messages` that the contract can handle. These messages represent the various commands or queries that can be sent to the smart contract by users or other contracts.

The following would be the prompt to get this file with the required messages created:

```
How do I create the msg.rs file to define the messages the contract will handle?
```
> Generate the `msg.rs` file for the lottery smart contract based on the `contract.rs` file. It should include:
>
> - An `InstantiateMsg` struct for initializing the contract.
> - An `ExecuteMsg` enum with variants executing required transactions
> - A `QueryMsg` enum with variant for querying poll results.
>
> Ensure that all structs and enums are serializable using `serde`.
## Error handling

The `error.rs` file is used to define custom error types for the contract. These custom error types help to provide more meaningful error messages and better error handling within the contract. By using specific error types, developers can more easily diagnose and handle issues that arise during the execution of the contract.

The following would be the prompt:

```
How do I create the error.rs file to define custom errors for the contract?
```

## Contract logic
> Generate the `error.rs` file based on the relevant errors used within the `contract.rs` file. It should also follow CosmWasm's best practices for error handling.
The main entry point for defining the core logic of the smart contract is stored in the `contract.rs` file. This file typically contains the primary functions that handle the execution of the contract's actions and queries. It orchestrates how the contract processes messages, manages state, and interacts with other modules of the project.
## Rectify any errors


The following would be the prompt:

```
How do I create the contract.rs file to implement the core logic of the contract?
```

## Library file

The `lib.rs` file serves as the central module for the contract. It typically includes declarations that bring together various components of the contract, making them accessible from a single entry point. This file often contains module imports, exports, and any necessary configurations or macros.

The following would be the prompt:

```
How do I create the lib.rs file to tie everything together?
```
There may be errors in the `contract.rs` and other files. To address these, hover over each error to see the details of the error and copy the details into ChatGPT and following its instructions to rectify the errors which might require some code changes. Once there are no more errors you can move to the next section to start the process of deploying and creating a new instance of your contract on chain.

## Compiling the contract

Expand Down

0 comments on commit 7e11ca8

Please sign in to comment.