Skip to content

Commit

Permalink
Restructuring the AI assistance section and addition of a new guide o…
Browse files Browse the repository at this point in the history
…n using ai to help with building a dapp frontend (#514)
  • Loading branch information
emperorjm authored Aug 5, 2024
1 parent c75b5b1 commit ac5afb6
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
objectID: developers_guides_ai-assistance_introduction
title: AI Assisted Fronted Development
description: How to use AI assistance to build dapp frontends on Archway
parentSection: Developers
parentSectionPath: /developers
---

# Overview

In this tutorial, you'll learn how to create a Lottery Dapp frontend using the `arch3.js` library and `React`. The AI will guide you through the entire process, from setting up your project to interacting with your smart contract on the Archway blockchain.

Please make sure you've gone through the following [guide](/developers/getting-started/install) to install all the tools required for developing on Archway. Also, make sure to go the [guide](/developers/guides/ai-assistance/ai-assited-smart-contract-development) on creating the Lottery smart contract.

## Key tips for interacting with ChatGPT AI

To successfully create and deploy the Lottery Dapp frontend using, 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.

## Archway custom GPT

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

## Initial setup

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 React project and set up the necessary dependencies. The following will therefore be the first prompt:

```
I want to build a frontend for my Lottery Dapp on the Archway blockchain using React and Arch3.js. The frontend should allow users to enter the lottery by paying a small fee, and an admin can draw a winner to receive the total collected fees.
I want to go through the process by creating step by step prompts with the first prompt being, how do I create a new React project and install Arch3.js along with other necessary packages?
```

The response should guide you with the commands and steps required for setting up your project.

## Create components and smart contract interactions

Along with the request to create the necessary components for entering the lottery, drawing a winner, and querying the pool and participants, you will also need to share the messages that makes up your smart contract with ChatGPT. This step helps ChatGPT understand how to interact with the contract.

The following could be an example of the messages in your smart contract's `msg.rs` file:

```rust
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
Enter {},
Draw {},
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
GetPool {},
GetParticipants {},
}
```

You would then make the following prompt, adding the code from your contract's `msg.rs` file:

```
Here are the messages defined in my smart contract:
[Code Here]
How do I create the necessary components in React to interact with my lottery contract using Arch3.js?
```

This should now give you a functioning dapp that you can actually plug in your `contract address` and wallet `mnemonic` to interact with your smart contract. Test it out and see if you have any issues. If there are errors, share with ChatGPT and update the code as required.

## Integrate with browser wallet

Instead of storing our wallet's mnomonic in the dapp, let's update the code to use our Keplr wallet for signing transactions.

The following would be the prompt:

```
Instead of storing my wallet's mnemonic in the dapp how can I use my Keplr browser wallet to sign transactions?
```

With these steps provided, your React application should now be integrated with Keplr, allowing you to sign transactions using their Keplr browser wallet. Ensure that the Keplr extension is installed in your browser and that you have selected the correct network for your application.

This is a basic setup to get you started with a frontend for your lottery contract using Arch3.js. You can extend this by adding error handling, state management, and more interactive UI elements. We will share other examples that utilize more boilerplate code and production ready solutions.

0 comments on commit ac5afb6

Please sign in to comment.