跳转到帖子
View in the app

A better way to browse. Learn more.

WEB3论坛社区

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

recommended_posts

发布于
  • 管理员

SPL 代币

在以太坊中,普通代币被一个叫ERC20的提案定了规范,可以认为普通代币合约统一叫做ERC20代币。

那么Solana世界里的ERC20代币是什么呢?答案就是SPL代币。

The Solana Program Library (SPL) is a collection of on-chain programs targeting the Sealevel parallel runtime.

SPL Token是 " Solana Program Library"中的一个组成部分,叫做"Token Program",简称为SPL Token。

所有的代币都有这个合约来管理,该合约代码在 https://github.com/solana-labs/solana-program-library/tree/master/token

代币信息

不同于以太坊中,一个代币就是一个合约。

SPL Token中,一个代币,仅仅是一个归Token合约管理的普通的Account对象,这个对象里面的二进制数据定义了 这个代币的基本属性。其结构为:

Copypub struct Mint {
        /// Optional authority used to mint new tokens. The mint authority may only be provided during
        /// mint creation. If no mint authority is present then the mint has a fixed supply and no
        /// further tokens may be minted.
        pub mint_authority: COption<Pubkey>,
        /// Total supply of tokens.
        pub supply: u64,
        /// Number of base 10 digits to the right of the decimal place.
        pub decimals: u8,
        /// Is `true` if this structure has been initialized
        pub is_initialized: bool,
        /// Optional authority to freeze token accounts.
        pub freeze_authority: COption<Pubkey>,
    }

相对有意义的就是supply表示总共的供应量,decimals表示代币的精度信息。

mint_wallet_account.png

SPL Token Account

那么每个用户的拥有的代币数量信息存在哪里呢?

这个合约又定义了一个账号结构,来表示某个地址含有某个代币的数量。

Copypub struct Account {
        /// The mint associated with this account
        pub mint: Pubkey,
        /// The owner of this account.
        pub owner: Pubkey,
        /// The amount of tokens this account holds.
        pub amount: u64,
        /// If `delegate` is `Some` then `delegated_amount` represents
        /// the amount authorized by the delegate
        pub delegate: COption<Pubkey>,
        /// The account's state
        pub state: AccountState,
        /// If is_native.is_some, this is a native token, and the value logs the rent-exempt reserve. An
        /// Account is required to be rent-exempt, so the value is used by the Processor to ensure that
        /// wrapped SOL accounts do not drop below this threshold.
        pub is_native: COption<u64>,
        /// The amount delegated
        pub delegated_amount: u64,
        /// Optional authority to close the account.
        pub close_authority: COption<Pubkey>,
    }

这里owner表示谁的代币,amount表示代币的数量。

spl_account.png

Account关系

所以整体结构是这样的:

spl_pda_account.png

这两个结构体都是SPL Token Program管理的Account对象,其自身所携带的数据,分别为代币信息,和 存储哪个代币的信息。

这样当需要进行代币的交易时,只需要相应用户的相应代币账号里面的amount即可。

创建帐户或登录后发表意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.