Create a token (ERC-20)¶
Two routes produce a standard ERC-20 on chain 77240. Both use OpenZeppelin Contracts 5.0.2 and solc 0.8.26.
- Install the PQWERAI Windows Wallet 0.6.0 and connect it to a node.
- Open Studio → Contract type: Token (ERC-20).
- Fill Name and symbol, Supply, optional Features, and the Owner (defaults to the selected account).
- Review shows every parameter, the fee and the chain ID; confirm with your password.
- Verify and track: the wallet compares the deployed runtime with its shipped artifact byte-for-byte, reads back name, symbol, supply and owner, and adds the token to Tokens.
The token template is precompiled (deterministic, zero warnings), so no compiler is needed. Studio can also deploy custom Solidity pasted from an editor or AI assistant; that code is labelled unaudited.
Prerequisites: the quickstart account and env.sh; the first contract setup.
install-openzeppelin.sh
# OpenZeppelin Contracts 5.0.2 (MIT): the version the Wallet Studio templates are compiled with.
# Run inside the project directory. Needs network access to GitHub once.
forge install OpenZeppelin/openzeppelin-contracts@v5.0.2 --no-git
src/PQToken.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
/// Example ERC-20 with an owner-only mint. Unaudited tutorial code.
contract PQToken is ERC20, Ownable {
constructor(string memory name_, string memory symbol_, uint256 initialSupply, address owner_)
ERC20(name_, symbol_)
Ownable(owner_)
{
_mint(owner_, initialSupply);
}
function mint(address to, uint256 amount) external onlyOwner {
_mint(to, amount);
}
}
deploy-token.sh
ME=$(cast wallet address --keystore "$KEYSTORE" --password-file "$PASSWORD_FILE")
W="--keystore $KEYSTORE --password-file $PASSWORD_FILE --rpc-url $RPC"
forge build
# 1,000,000 tokens (18 decimals) minted to ME, who is also the owner.
# --constructor-args consumes every following word, so it must come last.
forge create src/PQToken.sol:PQToken --broadcast $W \
--constructor-args "Tutorial Token" "TUT" 1000000000000000000000000 "$ME" | tee deploy.log
TOKEN=$(sed -n 's/^Deployed to: //p' deploy.log)
cast call "$TOKEN" "name()(string)" --rpc-url "$RPC"
cast call "$TOKEN" "totalSupply()(uint256)" --rpc-url "$RPC"
# Transfer 250 TUT, then read both balances.
BOB=0x000000000000000000000000000000000000bEEF
cast receipt "$(cast send "$TOKEN" "transfer(address,uint256)" "$BOB" 250000000000000000000 --async $W)" status --rpc-url "$RPC"
cast call "$TOKEN" "balanceOf(address)(uint256)" "$BOB" --rpc-url "$RPC"
cast call "$TOKEN" "balanceOf(address)(uint256)" "$ME" --rpc-url "$RPC"
# Owner-only mint. The same call from any other account reverts with OwnableUnauthorizedAccount.
cast receipt "$(cast send "$TOKEN" "mint(address,uint256)" "$BOB" 1000000000000000000 --async $W)" status --rpc-url "$RPC"
cast call "$TOKEN" "balanceOf(address)(uint256)" "$BOB" --rpc-url "$RPC"
Expected output:
Design notes¶
- Decimals. OpenZeppelin defaults to 18. Amounts on chain are integers:
250 TUT = 250 × 10^18. - Supply policy. This example has an owner-only
mint. Remove it (andOwnable) for a fixed supply. - Ownership. See Access control and ownership for two-step transfer and roles.
- Wallet display. The Windows Wallet discovers ERC-20 balances from
Transferevents and warns about tokens that impersonate native PQAI or use hidden characters in their names. - Explorer. The explorer indexes ERC-20 transfers (
/api/v1/tokens); it does not read token names or verify source yet.
Common errors¶
| Error | Cause |
|---|---|
OwnableUnauthorizedAccount(0x…) |
mint called by an account that is not the owner |
ERC20InsufficientBalance |
Transfer larger than the sender's balance |
Constructor argument count mismatch |
--constructor-args placed before other options |
Source "@openzeppelin/…" not found |
Library not installed, or remappings missing in foundry.toml |
Sources at 72057fe3ec: developers/examples/token/src/PQToken.sol · developers/examples/token/install-openzeppelin.sh · developers/examples/token/deploy-token.sh · apps/pqwerai-wallet-windows/README.md
Found a problem? Report a documentation issue · Build testnet-rc1+72057fe3ec