使用Anchor开发一个“Hello World”智能合约并将其部署到本地Solana测试网络(localhost)涉及以下步骤。这个过程假设你已经安装了Rust、Solana CLI、Node.js/npm,并且你的开发环境已经配置好了Solana的本地网络。
步骤 1: 安装Anchor
首先,确保已安装Anchor CLI。打开终端并运行以下命令:
npm install -g @project-serum/anchor-cli
步骤 2: 设置Solana本地网络
确保Solana本地网络运行中。如果未运行,使用以下命令启动:
步骤 3: 创建新的Anchor项目
在你希望的目录中,运行以下命令来创建一个新的Anchor项目:
anchor init hello_world --javascript
这将创建一个名为hello_world的新项目,并设置为使用JavaScript。进入项目目录:
步骤 4: 编写智能合约
在programs/hello_world/src/lib.rs中,编写你的智能合约代码。下面是一个简单的例子:
use anchor_lang::prelude::*;
declare_id!("Fg6PaFzntrfVLbzEY8YfVf2Xg3mBBoNARkSE1Le6RGD");
#[program]
pub mod hello_world {
use super::*;
pub fn say_hello(ctx: Context<SayHello>) -> ProgramResult {
msg!("Hello, world!");
Ok(())
}
}
#[derive(Accounts)]
pub struct SayHello {}
步骤 5: 构建项目
在项目根目录下运行:
anchor build
此命令将构建智能合约并生成一个针对Solana网络的BPF(Berkeley Packet Filter)程序。
步骤 6: 配置本地网络
确保你的Anchor.toml文件中的本地网络配置是正确的,通常这个步骤不需要修改。
步骤 7: 部署合约
在项目根目录下运行:anchor deploy
这将会编译你的程序(如果之前没有编译的话)并将其部署到本地Solana网络。
步骤 8: 测试合约
在tests/hello_world.js中,你可以编写测试脚本来调用你的合约。Anchor已经为你设置了一个测试框架。以下是调用say_hello函数的示例:
const anchor = require('@project-serum/anchor');
describe('hello_world', () => {
// Configure the client to use the local cluster.
anchor.setProvider(anchor.Provider.env());
it('Is initialized!', async () => {
// Add your test here.
const program = anchor.workspace.HelloWorld;
await program.rpc.sayHello({
accounts: {},
});
console.log("Said hello!");
});
});
运行测试:anchor test
这将执行测试脚本,调用智能合约,并在控制台输出“Hello, world!”。
以上步骤概述了使用Anchor开发和部署一个简单“Hello World”智能合约到本地Solana网络的过程。实际开发过程中可能需要进一步学习Anchor的高级功能和Solana的特性,以充分利用这个平台的能力。
常见问题
Error: failed to start validator: Failed to create ledger at test-ledger: blockstore error
ChatGPT
这个错误提示表明在尝试启动Solana测试验证器时遇到了问题,具体是无法在指定位置创建或访问ledger(账本)。这通常是因为以下几个原因之一:
- 权限问题:当前用户没有足够的权限写入指定的目录。确保你有权访问和写入
test-ledger目录。 - 目录已存在且无法覆盖:如果
test-ledger目录已经存在,并且由于某种原因(如权限问题或目录状态)无法被覆盖或写入。 - 磁盘空间不足:确保你的系统上有足够的磁盘空间来创建ledger。
- 文件系统问题:文件系统错误或损坏也可能导致这个问题,尤其是在写入操作中。
解决步骤
你可以按照以下步骤尝试解决这个问题:
检查权限
- 确保你有权限写入
test-ledger目录。如果需要,可以尝试使用sudo命令(对于Linux/macOS)或以管理员身份运行命令提示符(对于Windows)来启动验证器。
删除现有的test-ledger目录
-
如果
test-ledger目录已经存在,尝试删除它,然后重新启动验证器。可以使用以下命令删除(在Linux/macOS上):<div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span>sh</span><span class="" data-state="closed"><button class="flex gap-1 items-center">Copy code</button></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-sh"><span class="hljs-built_in">rm</span> -rf test-ledger </code></div></div>确保在执行此命令前了解它的作用,因为这将删除
test-ledger目录及其所有内容。
检查磁盘空间
- 确保你的设备有足够的磁盘空间。可以使用
df -h(在Linux/macOS上)查看磁盘空间使用情况。
尝试不同的目录
-
在启动测试验证器时,尝试指定一个不同的目录来存储ledger数据。可以通过
--ledger选项来指定目录,例如:<div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span>sh</span><span class="" data-state="closed"><button class="flex gap-1 items-center">Copy code</button></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-sh">solana-test-validator --ledger /path/to/new/ledger </code></div></div>
如果上述步骤都不能解决问题,可能需要进一步检查系统日志或Solana的日志文件来获取更多的错误信息。此外,重新安装Solana工具或重启计算机有时也可以解决一些看似复杂的问题。
![]()
你
zsh: command not found: solana-test-validator
ChatGPT
当你在终端中收到“zsh: command not found: solana-test-validator”这样的错误时,这通常意味着Solana命令行工具(CLI)没有正确安装,或者安装了但其可执行文件的路径没有添加到你的环境变量中。以下是解决这个问题的几个步骤:
1. 检查Solana CLI是否已安装
首先,确认是否已经安装了Solana CLI。可以通过运行以下命令来尝试查找Solana版本,以验证安装:
<div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span>sh</span><span class="" data-state="closed"><button class="flex gap-1 items-center">Copy code</button></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-sh">solana --version
</code></div></div>
如果这个命令返回了版本信息,那么Solana CLI已安装。如果返回了相同的“command not found”错误,说明需要安装或重新安装Solana CLI。
2. 安装Solana CLI
如果还没有安装Solana CLI,按照Solana官方文档中的指导进行安装:
<div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span>sh</span><span class="" data-state="closed"><button class="flex gap-1 items-center">Copy code</button></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-sh">sh -c <span class="hljs-string">"<span class="hljs-subst">$(curl -sSfL https://release.solana.com/v1.10.32/install)</span>"</span>
</code></div></div>
注意: 上述命令中的版本
v1.10.32只是一个例子,你应该从Solana的官方GitHub仓库或其官方文档中检查最新版本。
3. 确保Solana CLI的路径添加到了环境变量
安装Solana CLI后,确保安装路径被添加到了你的PATH环境变量中。安装脚本通常会自动做这一步,但有时可能需要手动添加。
-
查看当前的
PATH:<div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span>sh</span><span class="" data-state="closed"><button class="flex gap-1 items-center">Copy code</button></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-sh"><span class="hljs-built_in">echo</span> <span class="hljs-variable">$PATH</span> </code></div></div> -
如果安装路径不在
PATH中,你需要根据你的操作系统和shell类型(比如bash, zsh)将其添加。对于zsh,可以通过编辑~/.zshrc文件来添加:<div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span>sh</span><span class="" data-state="closed"><button class="flex gap-1 items-center">Copy code</button></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-sh"><span class="hljs-built_in">export</span> PATH=<span class="hljs-string">"<span class="hljs-variable">$PATH</span>:/path/to/solana/bin"</span> </code></div></div>确保替换
/path/to/solana/bin为Solana二进制文件实际所在的目录。 -
修改文件后,运行以下命令使更改生效:
<div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span>sh</span><span class="" data-state="closed"><button class="flex gap-1 items-center">Copy code</button></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-sh"><span class="hljs-built_in">source</span> ~/.zshrc </code></div></div>
4. 重新检查Solana CLI
再次运行solana --version来确认Solana CLI现在可以正确执行。
如果你遵循了上述步骤还是遇到问题,可能需要检查安装过程中是否有错误信息输出,或者咨询Solana的官方支持或社区寻求帮助。
![]()
你
Error: failed to start validator: Failed to create ledger at /sol: blockstore error 以上报错的原因如下: The problem was that macOS 13 had the wrong version of tar installed. You need to replace it with the homebrew version of gnu. Detailed instructions provided on stackexchange answer. 应该怎么解决?
ChatGPT
如果你遇到了因为macOS 13上的tar版本不正确导致的Solana验证器启动失败问题,根据你提到的Stack Exchange上的解决方案,你需要将macOS自带的tar替换为Homebrew版本的GNU tar。以下是详细的解决步骤:
步骤 1: 安装Homebrew(如果尚未安装)
如果你还没有安装Homebrew,可以通过在终端中运行以下命令来安装它:
<div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span>sh</span><span class="" data-state="closed"><button class="flex gap-1 items-center">Copy code</button></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-sh">/bin/bash -c <span class="hljs-string">"<span class="hljs-subst">$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)</span>"</span>
</code></div></div>
安装完成后,根据终端中的提示,运行命令以将Homebrew的二进制文件目录添加到你的PATH环境变量。
步骤 2: 安装GNU tar
使用Homebrew安装GNU版本的tar:
<div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span>sh</span><span class="" data-state="closed"><button class="flex gap-1 items-center">Copy code</button></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-sh">brew install gnu-tar
</code></div></div>
安装完成后,gtar命令将可用于调用GNU版本的tar。
步骤 3: 替换macOS的tar(可选)
为了让系统默认使用GNU版本的tar,你可以将其添加到你的PATH环境变量的前面。这可以通过修改你的shell配置文件(如.bash_profile, .bashrc, .zshrc等)来完成。
对于zsh用户(macOS的默认shell),你可以通过在~/.zshrc文件中添加以下行来实现:
<div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span>sh</span><span class="" data-state="closed"><button class="flex gap-1 items-center">Copy code</button></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-sh"><span class="hljs-built_in">export</span> PATH=<span class="hljs-string">"<span class="hljs-subst">$(brew --prefix gnu-tar)</span>/libexec/gnubin:<span class="hljs-variable">$PATH</span>"</span>
</code></div></div>
对于bash用户,如果你使用的是.bash_profile或.bashrc,过程相同:
<div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span>sh</span><span class="" data-state="closed"><button class="flex gap-1 items-center">Copy code</button></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-sh"><span class="hljs-built_in">export</span> PATH=<span class="hljs-string">"<span class="hljs-subst">$(brew --prefix gnu-tar)</span>/libexec/gnubin:<span class="hljs-variable">$PATH</span>"</span>
</code></div></div>
完成修改后,保存文件并运行source ~/.zshrc(或相应的配置文件)来使更改生效。
步骤 4: 验证修改
运行以下命令来验证现在使用的是GNU版本的tar:
<div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span>sh</span><span class="" data-state="closed"><button class="flex gap-1 items-center">Copy code</button></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-sh">tar --version
</code></div></div>
如果输出显示的是GNU tar的版本信息,则表示替换成功。
步骤 5: 重新尝试启动Solana验证器
在替换了tar版本之后,再次尝试启动Solana验证器。如果之前的问题是由于tar版本引起的,那么现在应该能够成功启动了。
这些步骤解决了由于macOS 13上tar版本问题导致的Solana验证器启动失败的问题。如果你在执行这些步骤后仍然遇到问题,可能需要进一步检查Solana验证器的日志输出,查找是否有其他潜在的问题。
![]()
你
Failed to get validator identity over RPC: HTTP status server error (502 Bad Gateway) for url (http://127.0.0.1:8899/)
ChatGPT
遇到“Failed to get validator identity over RPC: HTTP status server error (502 Bad Gateway) for url (http://127.0.0.1:8899/)”这样的错误信息时,通常表示你的Solana验证器或者本地Solana节点没有正确运行或者无法通过RPC接口进行通信。这可能是由几个不同的问题引起的,以下是一些可能的原因及其解决方法:
1. 验证器未运行
确保Solana验证器正在运行。如果你刚刚启动了验证器,可能需要等待一段时间直到它完全启动并且可以接受连接。你可以使用以下命令来启动Solana测试验证器:
<div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span>sh</span><span class="" data-state="closed"><button class="flex gap-1 items-center">Copy code</button></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-sh">solana-test-validator
</code></div></div>
2. 端口占用
如果端口8899已经被其他应用占用,Solana验证器就无法使用这个端口。你可以使用lsof或netstat工具来检查端口使用情况:
-
对于
lsof:<div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span>sh</span><span class="" data-state="closed"><button class="flex gap-1 items-center">Copy code</button></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-sh">lsof -i :8899 </code></div></div> -
对于
netstat(在Linux上):<div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span>sh</span><span class="" data-state="closed"><button class="flex gap-1 items-center">Copy code</button></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-sh">netstat -an | grep 8899 </code></div></div>
如果端口已被占用,你需要停止使用该端口的应用或者配置Solana验证器使用不同的端口。
3. 网络配置问题
如果你在配置文件中自定义了网络设置或者RPC端口,确保这些配置是正确的。Solana验证器默认使用8899端口进行RPC通信,如果你更改了端口,需要确保使用的URL反映了这一点。
4. RPC服务未启动
确保Solana验证器的RPC服务已经启动并且配置正确。在某些情况下,可能需要显式地启动RPC服务或者配置验证器以启用RPC接口。
5. 防火墙或安全软件阻止
确保你的防火墙或安全软件没有阻止对8899端口的访问。在某些系统或网络配置中,防火墙规则可能会阻止本地或远程对Solana验证器的访问。
解决方法
- 重启验证器:尝试停止当前运行的Solana验证器实例并重新启动它。
- 检查Solana日志:查看Solana验证器的日志输出,可能会有关于为什么RPC服务无法正常工作的线索。
- 更新Solana工具:确保你使用的是最新版本的Solana工具链。可以通过运行
solana-install update来更新Solana CLI工具。
如果以上方法都不能解决问题,建议查看Solana官方文档或社区论坛,看看是否有其他人遇到并解决了类似的问题。
你
如何把这句也加到~/.zshrc里 export PATH="/Users/mac/.local/share/solana/install/active_release/bin:$PATH"
anchor init hello_world --javascript Only x86_64 / Linux distributed in NPM package right now. Trying globally installed anchor. Could not find globally installed anchor, install with cargo.
ChatGPT
你遇到的错误信息表明,当前环境中没有找到通过NPM安装的anchor,同时也提示你anchor CLI目前在NPM包中只分发了对于x86_64架构的Linux版本。如果你在非Linux环境中(例如macOS或Windows),并尝试通过NPM安装anchor,可能会遇到兼容性问题。
要解决这个问题,你可以按照以下步骤使用Rust的包管理器cargo来安装anchor CLI。
安装Rust和Cargo
首先,确保你的系统上安装了Rust和Cargo。如果未安装,可以通过访问Rust官网来安装Rust,这将同时安装Cargo。
使用Cargo安装Anchor
安装好Rust和Cargo后,打开终端并运行以下命令来安装Anchor CLI:
cargo install --git https://github.com/coral-xyz/anchor --tag v0.26.0 anchor-cli --locked
这个命令将从GitHub上安装指定版本的anchor。请注意,上述命令中的--tag v0.24.2部分指定了anchor的版本,你应该替换为最新或者需要的版本。可以在Anchor的GitHub仓库中找到最新版本。
验证Anchor安装
安装完成后,你可以通过运行以下命令来验证anchor是否正确安装:
anchor --version
如果安装成功,该命令将输出anchor的版本信息。
如果遇到路径问题
安装完成后,如果直接运行anchor命令时终端提示找不到命令,可能需要将Cargo的二进制文件目录添加到你的PATH环境变量。Cargo通常会安装二进制文件到~/.cargo/bin目录。
你可以通过在~/.zshrc文件中添加以下行来更新你的PATH:
export PATH="$HOME/.cargo/bin:$PATH"
然后运行source ~/.zshrc使更改生效,或者重新开启一个终端窗口。
完成这些步骤后,你应该能够在任何目录下使用anchor命令了。
package `solana-program v1.18.3` cannot be built because it requires rustc 1.72.0 or newer, while the currently active rustc version is 1.68.0-dev Either upgrade to rustc 1.72.0 or newer, or use cargo update -p solana-program@1.18.3 --precise ver where `ver` is the latest version of `solana-program` supporting rustc 1.68.0-dev
ChatGPT
ChatGPT
这个错误信息表明你当前的Rust编译器版本(rustc 1.68.0-dev)不满足solana-program包版本1.18.3所需的最低Rust版本(rustc 1.72.0或更高)。为了解决这个问题,你有两个选择:
选项 1: 升级Rust到最新稳定版本
推荐的解决方案是更新你的Rust编译器到最新的稳定版本。这不仅可以解决当前的问题,还可以让你享受到Rust最新的特性和性能改进。可以通过以下命令来更新Rust:
<div class="dark bg-gray-950 rounded-md"><div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md"><span>sh</span><span class="" data-state="closed"><button class="flex gap-1 items-center"><svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" class="icon-sm"><path fill-rule="evenodd" clip-rule="evenodd" d="M12 4C10.8954 4 10 4.89543 10 6H14C14 4.89543 13.1046 4 12 4ZM8.53513 4C9.22675 2.8044 10.5194 2 12 2C13.4806 2 14.7733 2.8044 15.4649 4H17C18.6569 4 20 5.34315 20 7V19C20 20.6569 18.6569 22 17 22H7C5.34315 22 4 20.6569 4 19V7C4 5.34315 5.34315 4 7 4H8.53513ZM8 6H7C6.44772 6 6 6.44772 6 7V19C6 19.5523 6.44772 20 7 20H17C17.5523 20 18 19.5523 18 19V7C18 6.44772 17.5523 6 17 6H16C16 7.10457 15.1046 8 14 8H10C8.89543 8 8 7.10457 8 6Z" fill="currentColor"></path></svg>Copy code</button></span></div><div class="p-4 overflow-y-auto"><code class="!whitespace-pre hljs language-sh">rustup update
</code></div></div>
更新完成后,可以通过rustc --version命令来验证Rust编译器是否已经更新到最新版本。
选项 2: 使用兼容的solana-program版本
如果由于某些原因你无法或不想更新Rust版本,另一个解决方案是将solana-program包降级到一个与当前Rust版本兼容的版本。首先,你需要找出哪个版本的solana-program与你的Rust编译器兼容。这可能需要查看solana-program的文档或在其版本历史中搜索。
一旦确定了兼容的版本,你可以使用以下命令来更新Cargo.toml文件中的依赖项:
cargo update -p solana-program --precise <兼容的版本号>
请将<兼容的版本号>替换为实际的版本号。例如,如果版本1.17.0是兼容的,命令将是:
cargo update -p solana-program --precise 1.17.0
验证和构建项目
无论选择哪个解决方案,完成操作后都应该尝试重新构建你的项目来验证问题是否已解决:
cargo build
如果你更新了Rust版本,还可以运行rustc --version确认Rust编译器已成功升级。如果你选择降级solana-program版本,检查Cargo.lock文件确保依赖项已正确更新。
[重要!!!-1] solana测试账号
Wrote new keypair to /Users/mac/.config/solana/devnet.json
pubkey: 9XpKu6vMA8W38Uqc8985RZncaLxtavsNPEGJso8NsrK4
Save this seed phrase and your BIP39 passphrase to recover your new keypair:
february allow purchase verb sentence couch dune initial bounce say foil picture
solana-keygen pubkey /Users/mac/.config/solana/devnet.json
Config File: /Users/mac/.config/solana/cli/config.yml
RPC URL: https://api.devnet.solana.com
WebSocket URL: wss://api.devnet.solana.com/ (computed)
Keypair Path: /Users/mac/.config/solana/id.json
solana airdrop 1
spl-token create-token --decimals 6
Creating token Mtox6E21KxhS3TKUrzoqw3WvkwxPJxHx3Y5YvJs7uve under program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
Address: Mtox6E21KxhS3TKUrzoqw3WvkwxPJxHx3Y5YvJs7uve
Decimals: 6
Signature: 4e53MM8HR4uC8Dvj8fBsidK2s59omPbZfR8nFjCLtfyqSKNiVubNM6bBXDCmYWwdML1RpL6N8YUfARhAGbZqN79T
创建一个代币账户:要持有您铸造的代币,您需要一个代币账户:
spl-token create-account Mtox6E21KxhS3TKUrzoqw3WvkwxPJxHx3Y5YvJs7uve
spl-token create-account Mtox6E21KxhS3TKUrzoqw3WvkwxPJxHx3Y5YvJs7uve
Creating account 8QL844T45zXZqrjcsHD2uABfN9GogrCKyojuoyjcpg7m
Signature: 4qGyxKiZmMWNtjUG9rihHQkswT2iv7TWvGnUmDrEA8z4PHZDB3wzAjATvKKqjznJ6NsKDwdmNo874Aq8AkerDWRp
spl-token mint <令牌地址> <Mint数量>
spl-token mint Mtox6E21KxhS3TKUrzoqw3WvkwxPJxHx3Y5YvJs7uve 100000000
spl-token mint Mtox6E21KxhS3TKUrzoqw3WvkwxPJxHx3Y5YvJs7uve 100000000
Minting 100000000 tokens
Token: Mtox6E21KxhS3TKUrzoqw3WvkwxPJxHx3Y5YvJs7uve
Recipient: 8QL844T45zXZqrjcsHD2uABfN9GogrCKyojuoyjcpg7m
Signature: mKc7Zpd26joj3SLtuhK3ewycHrjNRCRpgckB85JUh8e34xgcEfLkvoTopgsYaWMBBbp7MNRiNpBjF8AXJVJGBww
spl-token balance <令牌地址>
spl-token balance Mtox6E21KxhS3TKUrzoqw3WvkwxPJxHx3Y5YvJs7uve
//禁用mint
spl-token authorize <令牌地址> mint --disable
spl-token transfer
spl-token transfer Mtox6E21KxhS3TKUrzoqw3WvkwxPJxHx3Y5YvJs7uve 90000000
========
测试网
solana config set --url https://api.testnet.solana.com
Config File: /Users/mac/.config/solana/cli/config.yml
RPC URL: https://api.testnet.solana.com
WebSocket URL: wss://api.testnet.solana.com/ (computed)
Keypair Path: /Users/mac/.config/solana/devnet.json
Commitment: confirmed
spl-token create-token --decimals 6
Creating token HNCvr2WshunTduPWhWNrxUGewJg66gn5TThzT5tvzfav under program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
Address: HNCvr2WshunTduPWhWNrxUGewJg66gn5TThzT5tvzfav
Decimals: 6
Signature: 4pP72j3WAyaw3oTxxjKTScRvXfcX5bHF69VDnigW17U9QVyLDDG1kFC3kzfuBmWU2F14mfh6FgQUXJFynudn9QMv
spl-token create-account HNCvr2WshunTduPWhWNrxUGewJg66gn5TThzT5tvzfav
Creating account 8DMXyNzPkLxFSdwZq9Ad61AdwSjDRSwQrsAdjbTqvEc2
Signature: 6LnRArnVWDAMKKrh7YC1wWwUHUZE3HiSci8SAw7jtAhZdyUfg7b1kr44YFRu2stgQx3VFcKnJMBs2MMiWfstpuJ
spl-token mint HNCvr2WshunTduPWhWNrxUGewJg66gn5TThzT5tvzfav 100000000
spl-token mint HNCvr2WshunTduPWhWNrxUGewJg66gn5TThzT5tvzfav 100000000
Minting 100000000 tokens
Token: HNCvr2WshunTduPWhWNrxUGewJg66gn5TThzT5tvzfav
Recipient: 8DMXyNzPkLxFSdwZq9Ad61AdwSjDRSwQrsAdjbTqvEc2
Signature: 5kePMvYgtYZDXzSuwXqGDoSC4N1511tiCPH6mUnP7tRahtL8ZyCcTn3rABKKLks6kJaTqbHqpHFQK3ReDmco8cKs
