diff --git a/docs/course/demos/solana-memo.tsx b/docs/course/demos/solana-tx-with-wallet.tsx similarity index 100% rename from docs/course/demos/solana-memo.tsx rename to docs/course/demos/solana-tx-with-wallet.tsx diff --git a/docs/course/demos/solana-tx.tsx b/docs/course/demos/solana-tx.tsx new file mode 100644 index 000000000..8eaa77c4a --- /dev/null +++ b/docs/course/demos/solana-tx.tsx @@ -0,0 +1,72 @@ +import React, { useState } from 'react'; +import { solanaDevnet, SolanaWeb3ConfigProvider } from '@ant-design/web3-solana'; + +import '@solana/web3.js'; + +import { + clusterApiUrl, + Connection, + Keypair, + LAMPORTS_PER_SOL, + PublicKey, + sendAndConfirmRawTransaction, + sendAndConfirmTransaction, + SystemProgram, + Transaction, + TransactionInstruction, +} from '@solana/web3.js'; +import { Button, Input } from 'antd'; + +const devnetEndpoint = `https://api.zan.top/node/v1/solana/devnet/${YOUR_ZAN_API_KEY}`; + +// const connection = new Connection(clusterApiUrl('devnet')); +const connection = new Connection(devnetEndpoint); +const programId = new PublicKey('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'); + +export default function App() { + const [memo, setMemo] = useState('test'); + + const writeMemo = async () => { + const keypair = Keypair.generate(); + console.log('public_key:', keypair.publicKey.toBase58()); + + const airdropSignature = await connection.requestAirdrop(keypair.publicKey, LAMPORTS_PER_SOL); + console.log('airdrop_signature:', airdropSignature); + + const latestBlockhash = await connection.getLatestBlockhash(); + await connection.confirmTransaction( + { + signature: airdropSignature, + blockhash: latestBlockhash.blockhash, + lastValidBlockHeight: latestBlockhash.lastValidBlockHeight, + }, + 'finalized', + ); + + const tx = new Transaction() + .add( + SystemProgram.transfer({ + fromPubkey: keypair.publicKey, + toPubkey: new PublicKey('4wztJ4CAH4GbAUopZrVk7nLvoAC3KAF6ttMMWfnBRG1t'), + lamports: 0.5 * LAMPORTS_PER_SOL, + }), + ) + .add( + new TransactionInstruction({ + keys: [{ pubkey: keypair.publicKey, isSigner: true, isWritable: false }], + programId: programId, + data: Buffer.from(memo, 'utf-8'), + }), + ); + + const signature = await sendAndConfirmTransaction(connection, tx, [keypair]); + console.log('signature:', signature); + }; + + return ( +
+ setMemo(e.target.value)} /> + +
+ ); +} diff --git a/docs/course/intro-call-contract-solana.md b/docs/course/intro-call-contract-solana.md index e882478e7..53f5e749a 100644 --- a/docs/course/intro-call-contract-solana.md +++ b/docs/course/intro-call-contract-solana.md @@ -2,11 +2,11 @@ nav: Course group: title: What is DApp? -order: 3 +order: 4 --- -# Call Solana Memo Contract +# Interact with Solana Contract -Memo Program 是 Solana 上的一个示例程序,它是一个简单的合约,用于在交易中添加备注信息。在这个示例中,我们将演示如何使用 Ant Design Web3 连接 Solana 网络,并调用 Memo 合约。 +> TODO - + diff --git a/docs/course/intro-call-contract-solana.zh-CN.md b/docs/course/intro-call-contract-solana.zh-CN.md index e882478e7..acf2d3e68 100644 --- a/docs/course/intro-call-contract-solana.zh-CN.md +++ b/docs/course/intro-call-contract-solana.zh-CN.md @@ -1,12 +1,29 @@ --- -nav: Course +nav: 课程 group: - title: What is DApp? -order: 3 + title: DApp 是什么? +order: 4 --- -# Call Solana Memo Contract +# 与 Solana 合约交互 -Memo Program 是 Solana 上的一个示例程序,它是一个简单的合约,用于在交易中添加备注信息。在这个示例中,我们将演示如何使用 Ant Design Web3 连接 Solana 网络,并调用 Memo 合约。 +DApp 与区块链合约的交互是 DApp 的核心功能之一。实现这一点并不困难,但是需要写一些逻辑。在这个示例中,我们将演示如何使用 Ant Design Web3 连接 Solana 网络,并调用 Memo 合约。 - +Memo Program 是 Solana 上的一个示例程序,它是一个简单的合约,用于在交易中添加备注信息。 + +我们接下来通过两种方式来演示如何与 Solana 合约交互: + +1. 不使用钱包,直接调用合约 +2. 使用钱包调用合约 + +无论使用哪种方式,都需要用到 `@solana/web3.js`,一个 Solana 官方提供的,用于与 Solana 区块链进行交互的 JavaScript 库。 + + + +## 直接调用合约 + + + +## 使用钱包调用合约 + +