320 个稳定版本

2.0.7 2024 年 8 月 24 日
2.0.3 2024 年 7 月 20 日
1.18.22 2024 年 8 月 9 日
1.18.20 2024 年 7 月 24 日
1.2.9 2020 年 7 月 3 日

#598 in 魔法豆

Download history 76/week @ 2024-05-03 146/week @ 2024-05-10 248/week @ 2024-05-17 16/week @ 2024-05-24 140/week @ 2024-05-31 161/week @ 2024-06-07 191/week @ 2024-06-14 257/week @ 2024-06-21 15/week @ 2024-06-28 154/week @ 2024-07-05 54/week @ 2024-07-12 277/week @ 2024-07-19 291/week @ 2024-07-26 224/week @ 2024-08-02 206/week @ 2024-08-09 145/week @ 2024-08-16

907 次每月下载

Apache-2.0

2MB
39K SLoC

分发 Solana 代币

用户可能希望多次迭代地向多个账户进行支付。用户将有一个包含公钥和代币数量的电子表格,以及一些将代币传输给他们并确保发送的代币数量不超过预期数量的过程。此处的命令行工具会自动化这个过程。

分发代币

将代币发送到 <RECIPIENTS_CSV> 中的接收者。

示例 recipients.csv

recipient,amount,lockup_date
3ihfUy1n9gaqihM5bJCiTAGLgWc5zo3DqVUS6T736NLM,42.0,
CYRJWqiSjLitBAcRxPvWpgX3s5TvmN2SuRY3eEYypFvT,43.0,
solana-tokens distribute-tokens --from <KEYPAIR> --input-csv <RECIPIENTS_CSV> --fee-payer <KEYPAIR>

示例交易日志之前

recipient,amount,finalized_date,signature
6Vo87BaDhp4v4GHwVDhw5huhxVF8CyxSXYtkUwVHbbPv,70.0,2020-09-15T23:29:26.879747Z,UB168XhBhecxzeD1w2ZRUhwTHpPSqv2WNh8NrZHqz1F2EqxxbSW6iFfVtsg3HkU9NX2cD7R92D8VRLSyArZ9xKQ

如果交易日志中尚未记录分发,则将代币发送到 <RECIPIENTS_CSV> 中的接收者。

solana-tokens distribute-tokens --from <KEYPAIR> --input-csv <RECIPIENTS_CSV> --fee-payer <KEYPAIR>

示例输出

Recipient                                     Expected Balance
3ihfUy1n9gaqihM5bJCiTAGLgWc5zo3DqVUS6T736NLM  42
UKUcTXgbeTYh65RaVV5gSf6xBHevqHvAXMo3e8Q6np8k  43

示例交易日志之后

solana-tokens transaction-log --output-path transactions.csv
recipient,amount,signature
6Vo87BaDhp4v4GHwVDhw5huhxVF8CyxSXYtkUwVHbbPv,70.0,2020-09-15T23:29:26.879747Z,UB168XhBhecxzeD1w2ZRUhwTHpPSqv2WNh8NrZHqz1F2EqxxbSW6iFfVtsg3HkU9NX2cD7R92D8VRLSyArZ9xKQ
3ihfUy1n9gaqihM5bJCiTAGLgWc5zo3DqVUS6T736NLM,42.0,2020-09-15T23:31:50.264241Z,53AVNEVpQBteJBRAKp6naxXsgESDjqe1ge9Dg2HeCSpYWTuGTLqHrBpkHTnpvPJURNgKWxkJfihuRa5STVRjL2hy
CYRJWqiSjLitBAcRxPvWpgX3s5TvmN2SuRY3eEYypFvT,43.0,2020-09-15T23:33:53.680821Z,4XsMfLx9D2ZxVpdJ5xdkV2w4X4SKEQ5zbQhcH4NcRwgZDkdRNiZjvnMFaWaWHUh5eF1LwFPpQdjn6mzSsiCVj3L7

计算应发送多少代币

列出预期分布列表和已发送交易记录之间的差异。

solana-tokens distribute-tokens --dry-run --input-csv <RECIPIENTS_CSV>

示例 recipients.csv

recipient,amount,lockup_date
6Vo87BaDhp4v4GHwVDhw5huhxVF8CyxSXYtkUwVHbbPv,80,
7aHDubg5FBYj1SgmyBgU3ZJdtfuqYCQsJQK2pTR5JUqr,42,

示例输出

Recipient                                     Expected Balance
6Vo87BaDhp4v4GHwVDhw5huhxVF8CyxSXYtkUwVHbbPv  10
7aHDubg5FBYj1SgmyBgU3ZJdtfuqYCQsJQK2pTR5JUqr  42

分发代币:转账金额

此工具还使将相同数量的代币传输到简单接收者列表变得简单。只需添加 --transfer-amount 参数来指定金额

示例 recipients.csv

recipient
6Vo87BaDhp4v4GHwVDhw5huhxVF8CyxSXYtkUwVHbbPv
7aHDubg5FBYj1SgmyBgU3ZJdtfuqYCQsJQK2pTR5JUqr
CYRJWqiSjLitBAcRxPvWpgX3s5TvmN2SuRY3eEYypFvT
solana-tokens distribute-tokens --transfer-amount 10 --from <KEYPAIR> --input-csv <RECIPIENTS_CSV> --fee-payer <KEYPAIR>

示例输出

Recipient                                     Expected Balance
6Vo87BaDhp4v4GHwVDhw5huhxVF8CyxSXYtkUwVHbbPv  10
7aHDubg5FBYj1SgmyBgU3ZJdtfuqYCQsJQK2pTR5JUqr  10
CYRJWqiSjLitBAcRxPvWpgX3s5TvmN2SuRY3eEYypFvT  10

分发抵押账户

通过抵押账户分发代币的方式与分发代币的方式类似。主要区别在于,新抵押账户是从现有账户中分割出来的。通过分割,新账户继承了原始账户的任何锁定或保管设置。

solana-tokens distribute-stake --stake-account-address <ACCOUNT_ADDRESS> \
    --input-csv <ALLOCATIONS_CSV> \
    --stake-authority <KEYPAIR> --withdraw-authority <KEYPAIR> --fee-payer <KEYPAIR>

目前,这将从每个分配中减去1 SOL,并将其存储在接收者地址中。这1 SOL可以用于支付委托股份等质押操作的交易费用。剩余的分配将存入质押账户。新的质押账户地址将在交易日志中输出。

分发SPL代币

分发SPL代币的工作方式与分发SOL非常相似,但需要使用--owner参数来签署交易。每个接收者账户必须是一个系统账户,该账户将拥有SPL代币铸币的关联代币账户。如果关联代币账户尚不存在,它将由费用支付者创建并资助。

将SPL代币发送到<RECIPIENTS_CSV>中的接收者。 注意: CSV期望SPL代币金额以原始格式(无小数)表示

示例 recipients.csv

recipient,amount
CYRJWqiSjLitBAcRxPvWpgX3s5TvmN2SuRY3eEYypFvT,75400
C56nwrDVFpPrqwGYsTgQxv1ZraTh81H14PV4RHvZe36s,10000
7aHDubg5FBYj1SgmyBgU3ZJdtfuqYCQsJQK2pTR5JUqr,42100
7qQPmVAQxEQ5djPDCtiEUrxaPf8wKtLG1m6SB1brejJ1,20000

在开始分发之前,您可以检查接收者的状态。您必须包括SPL代币铸币地址

solana-tokens spl-token-balances --mint <ADDRESS> --input-csv <RECIPIENTS_CSV>

示例输出

Token: JDte736XZ1jGUtfAS32DLpBUWBR7WGSHy1hSZ36VRQ5V
Recipient                                             Expected Balance            Actual Balance                Difference
CYRJWqiSjLitBAcRxPvWpgX3s5TvmN2SuRY3eEYypFvT                    75.400                      0.000                   -75.400
C56nwrDVFpPrqwGYsTgQxv1ZraTh81H14PV4RHvZe36s                    10.000  Associated token account not yet created
7aHDubg5FBYj1SgmyBgU3ZJdtfuqYCQsJQK2pTR5JUqr                    42.100                      0.000                   -42.100
7qQPmVAQxEQ5djPDCtiEUrxaPf8wKtLG1m6SB1brejJ1                    20.000  Associated token account not yet created

运行分发

solana-tokens distribute-spl-tokens --from <ADDRESS> --owner <KEYPAIR> \
    --input-csv <RECIPIENTS_CSV> --fee-payer <KEYPAIR>

示例输出

Total in input_csv: 147.5 tokens
Distributed: 0 tokens
Undistributed: 147.5 tokens
Total: 147.5 tokens
Recipient                                             Expected Balance
CYRJWqiSjLitBAcRxPvWpgX3s5TvmN2SuRY3eEYypFvT                    75.400
C56nwrDVFpPrqwGYsTgQxv1ZraTh81H14PV4RHvZe36s                    10.000
7aHDubg5FBYj1SgmyBgU3ZJdtfuqYCQsJQK2pTR5JUqr                    42.100
7qQPmVAQxEQ5djPDCtiEUrxaPf8wKtLG1m6SB1brejJ1                    20.000

计算应发送多少代币

与SOL一样,您可以使用--dry-run参数或solana-tokens balances列出预期分发列表与已发送交易记录之间的差异。

示例更新的recipients.csv

recipient,amount
CYRJWqiSjLitBAcRxPvWpgX3s5TvmN2SuRY3eEYypFvT,100000
C56nwrDVFpPrqwGYsTgQxv1ZraTh81H14PV4RHvZe36s,100000
7aHDubg5FBYj1SgmyBgU3ZJdtfuqYCQsJQK2pTR5JUqr,100000
7qQPmVAQxEQ5djPDCtiEUrxaPf8wKtLG1m6SB1brejJ1,100000

使用dry-run

solana-tokens distribute-tokens --dry-run --input-csv <RECIPIENTS_CSV>

示例输出

Total in input_csv: 400 tokens
Distributed: 147.5 tokens
Undistributed: 252.5 tokens
Total: 400 tokens
Recipient                                             Expected Balance
CYRJWqiSjLitBAcRxPvWpgX3s5TvmN2SuRY3eEYypFvT                    24.600
C56nwrDVFpPrqwGYsTgQxv1ZraTh81H14PV4RHvZe36s                    90.000
7aHDubg5FBYj1SgmyBgU3ZJdtfuqYCQsJQK2pTR5JUqr                    57.900
7qQPmVAQxEQ5djPDCtiEUrxaPf8wKtLG1m6SB1brejJ1                    80.000

或者

solana-tokens balances --mint <ADDRESS> --input-csv <RECIPIENTS_CSV>

示例输出

Token: JDte736XZ1jGUtfAS32DLpBUWBR7WGSHy1hSZ36VRQ5V
Recipient                                             Expected Balance            Actual Balance                Difference
CYRJWqiSjLitBAcRxPvWpgX3s5TvmN2SuRY3eEYypFvT                   100.000                    75.400                   -24.600
C56nwrDVFpPrqwGYsTgQxv1ZraTh81H14PV4RHvZe36s                   100.000                    10.000                   -90.000
7aHDubg5FBYj1SgmyBgU3ZJdtfuqYCQsJQK2pTR5JUqr                   100.000                    42.100                   -57.900
7qQPmVAQxEQ5djPDCtiEUrxaPf8wKtLG1m6SB1brejJ1                   100.000                    20.000                   -80.000

依赖项

~37–54MB
~1M SLoC