solana token合约
Posted mutourend
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了solana token合约相关的知识,希望对你有一定的参考价值。
1. 引言
Solana中的SPL token 类似于以太坊的ERC20 token,但是具体的token name 和token symbol不是在合约中定义,而是通过Solana Token Registry来注册。
2. create Fungible token
// 默认token decimal为9
$ spl-token create-token
Creating token BbhdMBBNfo6HQm2moVmmPkqpK8XcUYkcP85ZHx6ZX7bd
Fee payer, CiXLP94T6QBrEdevnJrGEDcN3iRaEWMKm7bv76ogpsZm, has insufficient balance: 0.0014716 required, 0 available
$ solana airdrop 1
Requesting airdrop of 1 SOL
Signature: EnfRnPpH4GjHsvu39HeHjo9j8SyU8V4decpopqh6FUXNbFqpt8QsCkr3Yp9Y34hyavMa6wSTEor5tZXmL6nAWys
1 SOL
$ solana airdrop 1
Requesting airdrop of 1 SOL
Signature: 4JNMM53tmHABAGT7QTTUcAwBKyneQUA2qQQRwqBGoJsrZKxFD744oFJwBecDAmRqdUzAWyEwzX2KFxdhr7jyTvHW
2 SOL
$ spl-token create-token
Creating token 43Anyfo9GqygRawy2yiMHm4dnkGM7xUJePg7vwaYX93b
Signature: vLq5u9u6AhfNwqQMrn3wkbRoTBZkhNZgXMNEPFSpxMQfHMikH8SSCSaeXffLieV7qDZwC1Fkm9De5VrmmpQ56bq
$ solana balance
1.9985284 SOL
$ spl-token supply 43Anyfo9GqygRawy2yiMHm4dnkGM7xUJePg7vwaYX93b
0
$ spl-token create-account 43Anyfo9GqygRawy2yiMHm4dnkGM7xUJePg7vwaYX93b
Creating account 2eyP8556eLNpto8Gy5fG8usVsuyakBheoJuuEK6BaA8P
Signature: 3CHZYLggKuuAQKht9ebKe1M2YPikEHPB1hu55EuN5j2qGkZ5twkVKABk3h5XUpqeKmRFT9KP5trqYfTBSLVq5am9
$ solana balance
1.99648412 SOL
$ spl-token balance 43Anyfo9GqygRawy2yiMHm4dnkGM7xUJePg7vwaYX93b
0
$ spl-token mint 43Anyfo9GqygRawy2yiMHm4dnkGM7xUJePg7vwaYX93b 100
Minting 100 tokens
Token: 43Anyfo9GqygRawy2yiMHm4dnkGM7xUJePg7vwaYX93b
Recipient: 2eyP8556eLNpto8Gy5fG8usVsuyakBheoJuuEK6BaA8P
Signature: 5EJDYAf1uosdwAxXDaEbYL8rRVRX22rfSfg4aAhcaF4yoxhoBhnP4CAREfzK4kemofrBuc79Npo1bZ1e7A4JGQQC
$ spl-token supply 43Anyfo9GqygRawy2yiMHm4dnkGM7xUJePg7vwaYX93b
100
$ spl-token balance 43Anyfo9GqygRawy2yiMHm4dnkGM7xUJePg7vwaYX93b
100
$ spl-token accounts
Token Balance
---------------------------------------------------------------
43Anyfo9GqygRawy2yiMHm4dnkGM7xUJePg7vwaYX93b 100
$ spl-token balance 2eyP8556eLNpto8Gy5fG8usVsuyakBheoJuuEK6BaA8P
Could not find token account 53fqx9oJZ8obcXDVseHwXHC7qZdbmhbFg5qBYD1Btb2k
$ solana balance
1.99647912 SOL
$ spl-token wrap 1
Wrapping 1 SOL into EQ3hcYhswbmKk2c9jWUSeUqXgk5iUzsXeA8Vc7hn1E44
Signature: 3VhdMVSr3A1uJgLiv5jpsFqEb4UzJuCtXxfi2BowGHguEYLG7P7rb8BY1gNfXFmZNVRE4wfRRcBLAQArmjUFC8cm
$ solana balance
0.99647412 SOL
$ spl-token wrap 0.5
Error: Account already exists: EQ3hcYhswbmKk2c9jWUSeUqXgk5iUzsXeA8Vc7hn1E44
$ solana balance
0.99647412 SOL
$ spl-token unwrap EQ3hcYhswbmKk2c9jWUSeUqXgk5iUzsXeA8Vc7hn1E44
Unwrapping EQ3hcYhswbmKk2c9jWUSeUqXgk5iUzsXeA8Vc7hn1E44
Amount: 1 SOL
Recipient: CiXLP94T6QBrEdevnJrGEDcN3iRaEWMKm7bv76ogpsZm
Signature: 445kmxuoPV84vKtLJEp2Rd9W975NxzRSXtu53E5vJHJDGAyDM7Y43gruhNJ7D5dTavjZJZY8R63dfH7s9Gs8ShmP
$ solana balance
1.99646912 SOL
$ solana address -k alice.json
6vLQ6VeUZcG6nUZkBumg5cgE8bT937Lg8xfGZLtxDdqC
$ spl-token transfer 43Anyfo9GqygRawy2yiMHm4dnkGM7xUJePg7vwaYX93b 50 6vLQ6VeUZcG6nUZkBumg5cgE8bT937Lg8xfGZLtxDdqC
Transfer 50 tokens
Sender: 2eyP8556eLNpto8Gy5fG8usVsuyakBheoJuuEK6BaA8P
Recipient: 6vLQ6VeUZcG6nUZkBumg5cgE8bT937Lg8xfGZLtxDdqC
Recipient associated token account: 7YJ28CP22GBaumwdfjg7y8Mb26e8UokU4dDgJ5oC6wow
Error: Recipient's associated token account does not exist. Add `--fund-recipient` to fund their account
$ solana balance
1.99646912 SOL
$ spl-token transfer 43Anyfo9GqygRawy2yiMHm4dnkGM7xUJePg7vwaYX93b 50 6vLQ6VeUZcG6nUZkBumg5cgE8bT937Lg8xfGZLtxDdqC --fund-recipient
Transfer 50 tokens
Sender: 2eyP8556eLNpto8Gy5fG8usVsuyakBheoJuuEK6BaA8P
Recipient: 6vLQ6VeUZcG6nUZkBumg5cgE8bT937Lg8xfGZLtxDdqC
Recipient associated token account: 7YJ28CP22GBaumwdfjg7y8Mb26e8UokU4dDgJ5oC6wow
Funding recipient: 7YJ28CP22GBaumwdfjg7y8Mb26e8UokU4dDgJ5oC6wow (0.00203928 SOL)
Signature: 38Y8x3uG9Nmw8zJSGTXDyELYn21nG6UKG2fiKc59uq1CqdQ9W2SJRsSyrMAsmcjpYBF9eobryD99563zjJf6uBKQ
3. create Non Fungible token
7. 注册token name和symbol
参考资料
[1] Solana token program
[2] How register name and symbol spl-token
以上是关于solana token合约的主要内容,如果未能解决你的问题,请参考以下文章
如何通过“@solana/web3.js”和“@solana/spl-token”调用 nft 程序?