Skip to content

Commit

Permalink
A number of changes to the AI assisted smart contract development docs (
Browse files Browse the repository at this point in the history
  • Loading branch information
emperorjm authored Oct 9, 2024
1 parent 7e11ca8 commit ecb358d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,55 @@ parentSection: Developers
parentSectionPath: /developers
---

# Overview
# AI assisted smart contract development with ChatGPT

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.
In this tutorial, you'll 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 especially the section of the guide to install the [Archway Developer CLI](/developers/getting-started/install#archway-developer-cli).
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 on installing the [Archway Developer CLI](/developers/getting-started/install#archway-developer-cli).

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

## Key tips for interacting with ChatGPT AI
## Key tips for interacting with ChatGPT

To successfully create and deploy the Lottery smart contract using the Archway Developer CLI, you will interact with the ChatGPT AI to get clear, concise, and accurate instructions.

- Be Specific: Clearly state what you need help with. The more specific your question, the better the response.
- Use Code Blocks: When requesting code snippets, use code blocks to format your request.
- Follow Instructions: Ensure you follow the instructions provided by ChatGPT closely to avoid errors.
- 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.
- **Be Specific**: Clearly state what you need help with. The more specific your question, the better the response.
- **Follow Instructions**: Ensure you follow the instructions provided by ChatGPT closely to avoid errors.
- **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.

## 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
## Building the smart 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.
- **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

We've created a custom GPT configured with a knowledge set that should help with building smart contracts on Archway. The custom GPT can be accessed [here](https://chatgpt.com/g/g-g9aIUiOOS-archway-smart-contract-engineer) and is the recommended GPT for building smart contracts on Archway.

## Initial prompt

You want to give ChatGPT an overview of what is to be built along with the requirements but still allowing you to go through individual prompts to do things step by step.

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. 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?
I want to go through the process creating step by step prompts with the first prompt being, how do I create a new project using the Archway Developer CLI with the minimal version of the Increment contract template?
```

The response should guide you with the commands and selections required for creating this blank project via the Archway Developer CLI.

## Create contract data structure

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.
Expand All @@ -86,7 +67,7 @@ The main entry point for defining the core logic of the smart contract is stored
The following would be the prompt:

> Generate the `contract.rs` file for the lottery smart contract.
> Please make sure to include a method for initializing the contract.
> Please make sure to include a method for initializing the contract and all the necessary entry points are created.
> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ For this project, we’ll utilize the [Archway Developer CLI](/developers/develo

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
## Building the smart 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.

Expand Down

0 comments on commit ecb358d

Please sign in to comment.