### Clone and Start Ant Design Web3 Project
Source: https://github.com/ant-design/ant-design-web3/blob/main/README.md
Clone the Ant Design Web3 repository from GitHub, install dependencies using pnpm, and start the development server.
```bash
$ git clone git@github.com:ant-design/ant-design-web3.git
$ cd ant-design-web3
$ pnpm i
$ pnpm start
```
--------------------------------
### Install @ant-design/web3-sui
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/sui/README.md
Install the required packages using npm.
```bash
npm install @ant-design/web3 @ant-design/web3-sui --save
```
--------------------------------
### Install Project Dependencies
Source: https://github.com/ant-design/ant-design-web3/blob/main/docs/course/dev-init.md
Navigate into the project directory and install all required npm packages after project creation.
```bash
cd ant-design-web3-demo
npm i
```
--------------------------------
### Install Dependencies
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/tron/README.md
Install the necessary packages for @ant-design/web3 and its TRON adapter.
```bash
npm install @ant-design/web3 @ant-design/web3-tron --save
```
--------------------------------
### Install Dependencies
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/ton/README.md
Install the necessary packages for Ant Design Web3 and the TON adapter.
```bash
npm install @ant-design/web3 @ant-design/web3-ton --save
```
--------------------------------
### Install @ant-design/web3 and @ant-design/web3-solana
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/solana/README.md
Install the necessary packages for Ant Design Web3 and its Solana adapter using npm.
```bash
npm install @ant-design/web3 @ant-design/web3-solana --save
```
--------------------------------
### Install @ant-design/web3
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/README.md
Use npm to install the package as a dependency in your project.
```bash
npm install @ant-design/web3
```
--------------------------------
### Install @ant-design/web3 and @ant-design/web3-bitcoin
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/bitcoin/README.md
Install the necessary packages for Bitcoin integration with Ant Design Web3.
```bash
npm install @ant-design/web3 @ant-design/web3-bitcoin
```
--------------------------------
### Install Ant Design Web3 dependencies
Source: https://context7.com/ant-design/ant-design-web3/llms.txt
Install the core library along with the Ethereum adapter and required peer dependencies.
```bash
npm install antd @ant-design/web3 @ant-design/web3-wagmi wagmi viem @tanstack/react-query
```
--------------------------------
### Install viem Dependency
Source: https://github.com/ant-design/ant-design-web3/blob/main/docs/course/dev-call-contract.md
Install the required viem library which provides low-level utilities for wagmi.
```bash
npm install viem
```
--------------------------------
### DefaultGuide API
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/connect-modal/index.md
Configuration for the newbie guide panel within the ConnectModal.
```APIDOC
## DefaultGuide
### Parameters
#### Request Body
- **title** (string) - Optional - Guide title
- **infos** (GuideInfo[]) - Optional - Guide info list
- **moreLink** (string) - Optional - More link
- **getWalletBtnText** (string) - Optional - Get wallet button text
- **moreLinkText** (string) - Optional - More link text
```
--------------------------------
### Install Solana Web3 dependencies
Source: https://github.com/ant-design/ant-design-web3/blob/main/docs/course/advanced-call-contract-solana.md
Install the required @solana/web3.js library version 1.x for blockchain interaction.
```shell
npm install @solana/web3.js@1
```
--------------------------------
### Install Ant Design Web3 Dependencies
Source: https://github.com/ant-design/ant-design-web3/blob/main/docs/guide/quick-start.zh-CN.md
Install the necessary Ant Design Web3 packages using npm or pnpm. Ensure Node.js v18 or higher is installed.
```bash
npm install antd @ant-design/web3 @ant-design/web3-wagmi wagmi viem @tanstack/react-query --save
```
--------------------------------
### Quick Connect Configuration
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/connect-button/index.zh-CN.md
Enables direct display of installed wallets and protocols on the button.
```tsx
```
--------------------------------
### Quick Connect Configuration
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/connect-button/index.md
Enables display of installed wallets and universal protocols directly on the button.
```tsx
```
--------------------------------
### Install Dependencies
Source: https://github.com/ant-design/ant-design-web3/blob/main/docs/course/dev-connect.md
Install necessary packages for wagmi integration with Ant Design Web3. This includes `@ant-design/web3-wagmi`, `wagmi`, `viem`, and `@tanstack/react-query`.
```shell
npm i @ant-design/web3-wagmi wagmi viem @tanstack/react-query --save
```
--------------------------------
### Custom Guide Panel
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/connect-modal/index.zh-CN.md
Provides custom content for the onboarding guide panel.
```tsx
```
--------------------------------
### Install @ant-design/web3-icons
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/icons/README.md
Use npm to add the icon library to your project dependencies.
```bash
npm install @ant-design/web3-icons --save
```
--------------------------------
### Check Node.js and npm Versions
Source: https://github.com/ant-design/ant-design-web3/blob/main/docs/course/dev-init.md
Verify that Node.js and npm are installed and meet the minimum version requirements for the project.
```bash
node -v # => v20.0.0+
npm -v # => 10.0.0+
npx -v # => 10.0.0+
```
--------------------------------
### Recommended Configuration
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/ethereum/index.md
Standard setup for DApps including EIP6963, ENS support, default wallets, WalletConnect, and quick connection.
```tsx
```
--------------------------------
### Install Web3 Icons
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/icons/index.md
Install the @ant-design/web3-icons package to use icons in your project. This command saves the package to your dependencies.
```bash
npm install @ant-design/web3-icons --save
# or
yarn add @ant-design/web3-icons
```
--------------------------------
### Install Ant Design Web3
Source: https://github.com/ant-design/ant-design-web3/blob/main/README.md
Install Ant Design Web3 and its peer dependency antd using npm.
```shell
npm i antd @ant-design/web3 --save
```
--------------------------------
### Install web3js Dependencies
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/ethereum-web3js/index.md
Install the necessary packages for using the web3js adapter with Ant Design Web3. This includes the core web3 package and the specific adapter.
```bash
npm install @ant-design/web3 @ant-design/web3-eth-web3js web3 --save
```
--------------------------------
### Configure WagmiWeb3ConfigProvider with Imports
Source: https://github.com/ant-design/ant-design-web3/blob/main/docs/course/dev-connect.md
Import `WagmiWeb3ConfigProvider` and other necessary wagmi components to set up the Ethereum adapter. This example shows the basic structure before adding components.
```typescript
import { createConfig, http } from "wagmi";
import { mainnet } from "wagmi/chains";
import { WagmiWeb3ConfigProvider } from "@ant-design/web3-wagmi";
import { Address } from "@ant-design/web3";
export default function Web3() {
return (
);
};
```
--------------------------------
### Basic Icon Usage
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/icons/index.md
Demonstrates the basic usage of icons from the @ant-design/web3-icons package. Ensure the package is installed before using.
```tsx
import { HeartFilled } from "@ant-design/web3-icons";
const App = () => (
<>
>
);
```
--------------------------------
### Basic Web3ConfigProvider Usage
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/web3-config-provider/index.md
Demonstrates the fundamental setup of Web3ConfigProvider to enable global configuration and state management for Ant Design Web3 components.
```typescript
import React from 'react';
import { Web3ConfigProvider } from '@ant-design/web3';
const App = () => (
{/* Your application components */}
);
export default App;
```
--------------------------------
### Basic Solana Usage
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/solana/index.md
Demonstrates the basic setup for connecting to Solana using Ant Design Web3 components. Ensure you have the necessary providers configured.
```typescript
import {
SolanaWeb3ConfigProvider,
useAccount,
useConnectWallet,
} from '@ant-design/web3-solana';
import { Button, ConnectButton } from '@ant-design/web3';
const App = () => {
return (
);
};
const AccountProfile = () => {
const { address } = useAccount();
const { connect, disconnect, connecting, connected } = useConnectWallet();
return (
);
};
export default App;
```
--------------------------------
### Using NFTImage with wagmi
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/nft-image/index.md
Integration example for fetching and displaying NFT data using wagmi hooks.
```tsx
```
--------------------------------
### Integrate Ant Design Web3 with Wagmi
Source: https://github.com/ant-design/ant-design-web3/blob/main/docs/guide/ant-design-web3.md
Example demonstrating the usage of Ant Design Web3 components with the Wagmi adapter.
```tsx
```
--------------------------------
### Basic CryptoPrice Usage
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/crypto-price/index.md
Demonstrates the fundamental usage of the CryptoPrice component. No specific setup or imports are required beyond standard React and Ant Design Web3 integration.
```typescript
import { CryptoPrice } from '@ant-design/web3';
export default () => {
return (
);
};
```
--------------------------------
### Solana Transaction Without Wallet
Source: https://github.com/ant-design/ant-design-web3/blob/main/docs/course/advanced-call-contract-solana.md
This example demonstrates how to send a Solana transaction, including a transfer and a memo instruction, by signing with a private key. It's useful for debugging on test networks. Ensure you have test tokens or sufficient balance.
```typescript
import {
Keypair,
Transaction,
SystemProgram,
sendAndConfirmTransaction,
} from "@solana/web3.js";
const writeMemo = async () => {
// 1. Generate a new keypair
const keypair = Keypair.generate();
const publicKey = keypair.publicKey;
const privateKey = keypair.secretKey;
// 2. Obtain test tokens (optional, if account has no balance)
// const connection = new Connection(clusterApiUrl("devnet"));
// await connection.requestAirdrop(publicKey, 2 * LAMPORTS_PER_SOL);
// await confirmTransaction(connection, signature, "confirmed");
// 3. Create a transfer instruction
const transferInstruction = SystemProgram.transfer({
fromPubkey: publicKey,
toPubkey: new PublicKey("61QgmBmUw1Nekq7wGXtA7CCETUcbmTBJPjDWGLSrPqRK"), // Replace with a valid recipient
lamports: 100000000, // 0.1 SOL
});
// 4. Create a memo instruction
const memoInstruction = new TransactionInstruction({
keys: [{ pubkey: publicKey, isSigner: true, isWritable: false }],
programId: new PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"), // Memo program ID
data: Buffer.from("Hello Ant Design Web3!"),
});
// 5. Create a transaction and add instructions
const transaction = new Transaction().add(transferInstruction, memoInstruction);
// 6. Send and confirm the transaction
try {
const signature = await sendAndConfirmTransaction(connection, transaction, [keypair]);
console.log("Transaction sent and confirmed:", signature);
// You can view the transaction details on a blockchain explorer:
// console.log(`https://solscan.io/tx/${signature}?cluster=devnet`);
} catch (error) {
console.error("Transaction failed:", error);
}
};
// To run this example, you would need to:
// 1. Install @solana/web3.js and @ant-design/web3-solana
// 2. Set up a Solana connection (e.g., to devnet)
// 3. Uncomment and configure the airdrop part if needed
// 4. Call the writeMemo() function
```
--------------------------------
### Supporting Multiple Solana Networks
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/solana/index.md
Configure support for different Solana networks by defining the `chains` property in `SolanaWeb3ConfigProvider`. This example includes the Solana mainnet.
```typescript
import {
SolanaWeb3ConfigProvider,
useAccount,
useConnectWallet,
} from '@ant-design/web3-solana';
import { Button, ConnectButton } from '@ant-design/web3';
import { mainnet } from '@solana/web3.js'; // Import Solana mainnet
const App = () => {
return (
);
};
const AccountProfile = () => {
const { address } = useAccount();
const { connect, disconnect, connecting, connected } = useConnectWallet();
return (
);
};
export default App;
```
--------------------------------
### Sui Web3 Component Examples
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/sui/index.md
Demonstrates the usage of various Ant Design Web3 components adapted for the Sui blockchain.
```tsx
import {
SuiWeb3ConfigProvider,
ConnectButton,
WalletInfo,
BalanceDisplay,
SuiComponentsConfigProvider,
} from '@ant-design/web3-sui';
export default () => (
{/* More Sui specific components */}
);
```
--------------------------------
### Basic Address Usage
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/address/index.zh-CN.md
Demonstrates the fundamental usage of the Address component. No specific setup is required beyond importing the component.
```tsx
import React from 'react';
import { Address } from '@ant-design/web3';
const App: React.FC = () => (
);
```
--------------------------------
### Basic WagmiWeb3ConfigProvider Setup
Source: https://github.com/ant-design/ant-design-web3/blob/main/docs/course/dev-connect.md
Integrate `WagmiWeb3ConfigProvider` into your React application to adapt wagmi for Ant Design Web3. This provider automatically creates a wagmi configuration.
```typescript
import { WagmiWeb3ConfigProvider } from '@ant-design/web3-wagmi';
import { Address } from "@ant-design/web3";
export default function Web3() {
return (
);
};
```
--------------------------------
### Install Ant Design Web3 Dependencies
Source: https://github.com/ant-design/ant-design-web3/blob/main/docs/course/dev-init.md
Add the core Ant Design Web3 package and its related components to your project's dependencies.
```bash
npm i @ant-design/web3 --save
```
--------------------------------
### Using Built-in Language Packs
Source: https://github.com/ant-design/ant-design-web3/blob/main/docs/guide/intl.zh-CN.md
Utilize the pre-built language packs provided by `@ant-design/web3` for common languages. This simplifies setup for supported locales.
```typescript
import { Web3ConfigProvider } from '@ant-design/web3';
import { enUS } from 'date-fns/locale';
const App = () => (
{/* Your application components */}
);
```
--------------------------------
### Customizing Wallet Information
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/solana/index.md
Allows customization of wallet information when built-in wallets don't meet requirements. This example shows a basic structure for a custom wallet.
```typescript
import {
SolanaWeb3ConfigProvider,
useAccount,
useConnectWallet,
} from '@ant-design/web3-solana';
import { Button, ConnectButton } from '@ant-design/web3';
import { Wallet } from '@ant-design/web3';
// Define your custom wallet structure
interface CustomWallet extends Wallet {
// Add custom properties if needed
}
const myCustomWallet: CustomWallet = {
name: 'My Custom Wallet',
icon: 'url_to_your_icon.png',
// Implement necessary methods like connect, disconnect, etc.
// This is a simplified example; actual implementation will depend on the wallet's SDK
connect: async () => { console.log('Connecting custom wallet...'); return { address: 'custom_address' }; },
disconnect: async () => { console.log('Disconnecting custom wallet...'); },
// ... other required methods like getAccounts, signMessage, etc.
};
const App = () => {
return (
);
};
const AccountProfile = () => {
const { address } = useAccount();
const { connect, disconnect, connecting, connected } = useConnectWallet();
return (
);
};
export default App;
```
--------------------------------
### Implement USDT/USDC Payments with Ant Design Web3 Adapter
Source: https://github.com/ant-design/ant-design-web3/blob/main/docs/guide/payment-in-usdt.md
Use this adapter to connect to various blockchains and support USDT/USDC payments simultaneously. Ensure you have the necessary dependencies installed.
```typescript
import { ConnectButton, useAccount, useBalance, useChainId } from '@ant-design/web3';
import { useState, useEffect } from 'react';
import { message, Spin } from 'antd';
import { formatUnits } from 'ethers';
import { useUSDT } from '@ant-design/web3/es/hooks/useUSDT';
const USDT_ADDRESS = {
1: '0xdAC17F95823f0E192317472194A3247049841761',
5: '0x912CE595472E507f989312016773063391175795',
};
const Page = () => {
const { address, chain } = useAccount();
const { data: balance, isLoading: balanceLoading } = useBalance();
const chainId = useChainId();
const { getUSDTContract } = useUSDT();
const [usdtBalance, setUsdtBalance] = useState('0');
const [usdtLoading, setUsdtLoading] = useState(false);
useEffect(() => {
const fetchUSDTBalance = async () => {
if (!address || !chainId) return;
setUsdtLoading(true);
try {
const usdtAddress = USDT_ADDRESS[chainId as keyof typeof USDT_ADDRESS];
if (!usdtAddress) {
message.error('Unsupported chain');
setUsdtLoading(false);
return;
}
const usdtContract = getUSDTContract(usdtAddress);
const res = await usdtContract.balanceOf(address);
setUsdtBalance(formatUnits(res));
} catch (error) {
message.error('Failed to fetch USDT balance');
console.error(error);
} finally {
setUsdtLoading(false);
}
};
fetchUSDTBalance();
}, [address, chainId, getUSDTContract]);
return (
);
};
export default Page;
```
--------------------------------
### Create Next.js Project
Source: https://github.com/ant-design/ant-design-web3/blob/main/docs/course/dev-init.md
Initialize a new Next.js project with a specific version of create-next-app to ensure tutorial compatibility. This command sets up the basic structure for a React application.
```bash
npx create-next-app@14.0.4 # We specify the version of create-next-app as 14.0.4 to avoid the differences caused by the upgrade affecting the details of the tutorial
```
--------------------------------
### EIP6963 Wallet Discovery
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/ethereum/index.md
Enables automatic wallet detection to prevent conflicts when multiple wallets are installed.
```tsx
```
--------------------------------
### Configure Bitcoin Web3 Provider and Connect Button
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/bitcoin/README.md
Set up the BitcoinWeb3ConfigProvider with desired wallets and render the ConnectButton for Bitcoin connections.
```tsx
import { ConnectButton, Connector } from '@ant-design/web3';
import {
BitcoinWeb3ConfigProvider,
OkxWallet,
UnisatWallet,
XverseWallet,
} from '@ant-design/web3-bitcoin';
const App: React.FC = () => {
return (
);
};
export default App;
```
--------------------------------
### NFTCard with Wagmi Integration
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/nft-card/index.md
Integrates NFTCard with wagmi for blockchain data fetching. Requires wagmi setup.
```tsx
import { NFTCard } from '@ant-design/web3';
import { useAccount } from 'wagmi';
const App = () => {
const { address } = useAccount();
return (
);
};
```
--------------------------------
### 执行 changeset 命令
Source: https://github.com/ant-design/ant-design-web3/blob/main/docs/guide/changelog.zh-CN.md
在项目根目录下运行 changeset 命令以启动变更记录流程。
```bash
MacBook-Pro ant-design-web3 % pnpm changeset
> @ant-design/web3-docs@0.0.0 changeset ant-design-web3
> changeset
```
--------------------------------
### Recommended Solana Configuration
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/solana/index.md
Use this configuration for a rich set of features including automatic wallet detection, balance display, default wallet support (Phantom, OKX) with download guidance, quick connection, simplified UI, and custom RPC.
```typescript
import {
SolanaWeb3ConfigProvider,
useAccount,
useConnectWallet,
} from '@ant-design/web3-solana';
import { Button, ConnectButton } from '@ant-design/web3';
import { notification } from 'antd';
const App = () => {
return (
{
// You can use the chain information to configure the RPC URL
// For example, you can use the chain ID to select the RPC URL
// Or you can use the chain name to select the RPC URL
// For more information, please refer to the Solana documentation
// https://solana-labs.github.io/solana-web3.js/v1.x/classes/Connection.html#constructor
return 'https://rpc.ankr.com/solana';
}}
>
);
};
const AccountProfile = () => {
const { address } = useAccount();
const { connect, disconnect, connecting, connected } = useConnectWallet();
return (
);
};
export default App;
```
--------------------------------
### 创建 Next.js 项目
Source: https://github.com/ant-design/ant-design-web3/blob/main/docs/course/dev-init.zh-CN.md
使用指定版本的 create-next-app 初始化项目。
```bash
npx create-next-app@14.0.4 # 我们指定 create-next-app 的版本为 14.0.4,避免升级带来的差异影响教程的细节
```
--------------------------------
### Recommended Sui Configuration
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/sui/index.md
Use this configuration for most Sui dApps to automatically detect wallets, display balances and SNS, and simplify connection with quickConnect in simple mode.
```tsx
import { SuiWeb3ConfigProvider } from '@ant-design/web3-sui';
export default () => (
{/* Your app content */}
);
```
--------------------------------
### Customizing NFT Metadata Fetching
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/nft-image/index.md
Example of providing a custom getNFTMetadata function to handle specific metadata requirements.
```tsx
```
--------------------------------
### Get Ethereum network chain ID
Source: https://github.com/ant-design/ant-design-web3/blob/main/docs/course/intro-call-contract.md
Retrieves the current network ID via the injected window.ethereum provider.
```js
await window.ethereum.request({ method: 'eth_chainId' }); // 0x1 represents the Ethereum mainnet
```
--------------------------------
### Adding More Solana Wallets
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/solana/index.md
Manually configure additional wallets by importing them from `@solana/wallet-adapter-ADAPTER_YOUR_NEED`. This helps reduce package size.
```typescript
import {
SolanaWeb3ConfigProvider,
useAccount,
useConnectWallet,
} from '@ant-design/web3-solana';
import { Button, ConnectButton } from '@ant-design/web3';
import { PhantomWallet, OkxWallet } from '@solana/wallet-adapter-wallets'; // Example wallets
const App = () => {
return (
);
};
const AccountProfile = () => {
const { address } = useAccount();
const { connect, disconnect, connecting, connected } = useConnectWallet();
return (
);
};
export default App;
```
--------------------------------
### Ethers.js v5 Compatibility
Source: https://github.com/ant-design/ant-design-web3/blob/main/packages/web3/src/ethereum-ethersjs/index.md
Instructions and code example for using Ant Design Web3 with legacy versions of Ethers.js (v5.x).
```APIDOC
## Ethers.js v5 Compatibility
### Description
If you are a user of `ethers@5.x`, you can manually install the v5 version of ethers and modify the adapter import method. Versions prior to v5 are no longer supported. It is recommended to use after upgrading to the latest version.
### Installation
```bash
npm install @ant-design/web3 @ant-design/web3-ethers-v5 ethers@legacy-v5
# or
yarn add @ant-design/web3 @ant-design/web3-ethers-v5 ethers@legacy-v5
```
### Usage
```tsx
import { EthersWeb3ConfigProvider, useEthersProvider } from '@ant-design/web3-ethers-v5'; // importing the adapter for ethers@5.x
const Component = () => {
const provider = useEthersProvider();
// do something with provider
return (