Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of the cw20 token creation guide #496

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 186 additions & 0 deletions content/2.developers/3.guides/11.cw20-token/1.introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
---
objectID: developers_guides_cw20
title: Getting started
description: This guide will walk developers through the steps required to create, deploy, and interact with a CW20 token contract
parentSection: Developers
parentSectionPath: /developers
---

# Create a CW20 token on Archway

In this tutorial, you'll learn how to create a `CW20` token on the Archway network. `CW20` is the CosmWasm standard for fungible tokens, similar to `ERC-20` on Ethereum. Fungible tokens are interchangeable units, much like fiat currency - each token is equivalent in value and functionality to any other of the same type.

The `CW20` specification outlines standard functions and characteristics for these tokens, including transfers, balance checks, and spender approvals. For a detailed overview, you can refer to the official [CW20 documentation](https://github.com/CosmWasm/cw-plus/blob/main/packages/cw20/README.md).

By following the `CW20` standard, you ensure your tokens will be compatible with a wide range of wallets, exchanges, and other smart contracts in the CosmWasm ecosystem, promoting interoperability and uniformity.


## Project setup

For this tutorial, ensure you have the [Archway Developer CLI](/developers/developer-tools/developer-cli) installed. Additionally, you need to [create an account](/developers/getting-started/setup#creating-an-account) and [fund](/developers/guides/faucet) this account with tokens to deploy your contract on-chain.

The Archway Developer CLI allows you to create projects using predefined templates as starting points. For this guide, we will create a project using the [**CW20 Base**](https://github.com/archway-network/archway-templates/tree/main/cw20/base) contract template.

In your terminal, enter the following command:

```sh
archway new
```

You will be prompted to enter the following details:
- Enter the name of the new project
- Select a chain to use (for this tutorial, we will use “Archway Testnet”)
- Choose a name for your contract
- Choose a starter template (select “CW20”)

After selecting the starter template, the Archway Developer CLI will set up your new project.

The following is an example of the output:

```
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.18s
Running `/Users/johndoe/cw20/cw20test2/target/debug/schema`
Exported the full API as /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/cw20test2.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/instantiate.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/execute.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/query.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/response_to_all_accounts.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/response_to_all_allowances.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/response_to_all_spender_allowances.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/response_to_allowance.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/response_to_balance.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/response_to_download_logo.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/response_to_marketing_info.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/response_to_minter.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/response_to_token_info.json
✅ Project cw20test2 created and configured for the chain constantine-3

Checking for updates...
```

## Build your contract

Before deploying your `CW20` token contract to the Archway network, you need to compile it into an optimized WebAssembly (Wasm) binary. This process requires [Docker](/developers/getting-started/install#docker), so ensure you have it installed and running on your system.

Follow these steps to build your contract:

- Navigate to your project directory in the terminal.
- Run the build command: `archway contracts build`

The following is an example of the output:

```
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.88s
Running `/Users/johndoe/cw20/cw20test2/target/debug/schema`
Removing "/Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/cw20test2.json" …
Exported the full API as /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/cw20test2.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/instantiate.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/execute.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/query.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/response_to_all_accounts.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/response_to_all_allowances.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/response_to_all_spender_allowances.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/response_to_allowance.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/response_to_balance.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/response_to_download_logo.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/response_to_marketing_info.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/response_to_minter.json
Exported /Users/johndoe/cw20/cw20test2/contracts/cw20test2/schema/raw/response_to_token_info.json

✅ Schemas generated
```

## Store contract on-chain

After building your optimized Wasm binary, you're ready to deploy your contract to the Archway network. Follow these steps:

- Ensure you have sufficient tokens in your wallet to cover transaction fees.
- Run the store command:
```
archway contracts store [CONTRACT]
```
Replace [CONTRACT] with the name of your contract.
- When prompted, enter the `name` or `address` of the account that will send the transaction.
- The Archway Developer CLI will then submit the transaction to store your contract on-chain.

Note: This process uploads your contract's bytecode to the blockchain, making it available for instantiation. However, it does not yet create an instance of your contract.

The following is an example of the output:

```
✔ Enter the name or address of the account that will send the transaction … mywallet
Uploading optimized wasm for contract cw20
Chain: constantine-3
Signer: mywallet
✅ Contract pepe.wasm uploaded
Code Id: 3109
Transaction: https://testnet.archway.explorers.guru/transaction/8AF06902EB3DAFDC328B30B94BE978FDC683B3A562B5E655D54C2278F008EB2C
```

## Instantiate a new token

Once your contract is stored on-chain, the next step is to create an instance of your CW20 token. This process, known as instantiation, involves setting up the initial parameters that will define your token. This process involves setting several parameters:

1. Required Parameters:
- `name`: Full name of the token (e.g., "Shiba Inu")
- `symbol`: Ticker symbol (e.g., "SHIB")
- `decimals`: Number of decimal places for token division
- `initial_balances`: Array of addresses and their initial token allocations

2. Optional Parameters:
- `mint`: Minting configuration (minter address and optional cap)
- `marketing`: Token metadata (project, description, marketing address, logo)

For detailed parameter information, refer to the `InstantiateMsg` struct in the [contract source code](https://github.com/archway-network/archway-templates/blob/main/cw20/base/src/msg.rs#L19-L25).

To instantiate your token, use the following command structure:

```
archway contracts instantiate [CONTRACT_NAME] --args '[INSTANTIATION_ARGS]'
```

Example:

```
archway contracts instantiate shiba-inu --args '{
"name": "Shiba Inu",
"symbol": "SHIB",
"decimals": 6,
"initial_balances": [
{
"address": "archway12qj4v8jg5pxk6gsqct09sf9szhwql69xmf9fh4",
"amount": "1000000000000"
}
],
"mint": {
"minter": "archway12qj4v8jg5pxk6gsqct09sf9szhwql69xmf9fh4",
"cap": "1000000000000"
},
"marketing": {
"project": "Dog meme token",
"description": "Dog meme token",
"marketing": "archway12qj4v8jg5pxk6gsqct09sf9szhwql69xmf9fh4",
"logo": {
"url": "https://upload.wikimedia.org/wikipedia/en/5/53/Shiba_Inu_coin_logo.png"
}
}
}'
```

This command will create a new instance of your CW20 token with the specified parameters.

The following is an example of the output:

```
Instantiating contract cw20test2
Chain: constantine-3
Code: 3183
Label: cw20test2-0.1.0
Admin: archway12qj4v8jg5pxk6gsqct09sf9szhwql69xmf9fh4
Signer: mywallet

✅ Contract cw20test2-0.1.0 instantiated
Address: archway182mpl0nlhl2k3hhec2z5wjvrqq55x3f6qq5akjl2tjqdrluh95csr4s00q
Transaction: https://testnet.archway.explorers.guru/transaction/2213EF7675AC3A660F20DBBFFF0915523E4B0948D40CFDD6396D928F66574316
```

Loading