How to Fetch Newly Minted Tokens with Helius
Introduction
Solana memecoins have been making headlines lately, with $WIF breaking $3.5 billion and Boden reaching $300 million. Popcat and Wen recently surpassed the $350 million mark. Slerf has also surpassed all Ethereum-based exchanges in trading volume within its first day. After BONK's boom last November, Solana sees more new tokens being created than ever. There has been a double increase in the number of new tokens minted on-chain over the past three months using the Solana Program Library (SPL) Standard, as seen from Solscan data.
This article explores how tokens are created on Solana, what SPL tokens are, and how to monitor new tokens and retrieve their metadata using Helius.
How are Tokens Created on Solana?
Solana supports both native SOL and other tokens. The Solana Program Library (SPL) defines common standards for fungible and non-fungible tokens (NFTs) on Solana. Unlike Ethereum, where different standards are set for different types of non-fungible (ERC-721) and fungible tokens (ERC-20), the Solana Program Library doesn’t have a specially computed standard for the different token types.
Token Program
The standard implementation for fungible and non-fungible tokens (NFTs) on Solana is Token Program. It provides functionality such as creating new token types and accounts, transferring and burning tokens, and more. The Token program is complete, and no plans exist to add new functionality. There may be changes to fix important/breaking bugs.
However, the Token Program is limited— developers must fork it to add new functionality, making transactions more complicated and risky. To address this, Solana introduced Token-2022, a suite of additional features and enhancements like:
- Mint Extensions: confidential transfers, transfer fees, closing mint, interest-bearing tokens, non-transferable tokens, permanent delegate, transfer hook, metadata pointer, metadata.
- Account Extensions: memo required on incoming transfers, immutable ownership, default account state, CPI guard.
To learn more about Token-2022, refer to this article.
Solana's Token Program allows us to create mint accounts and token accounts. Mint accounts contain global information about a token, while token accounts store the relationship between a wallet and a mint account. You can create tokens using the following code or the spl-token-cli. For example, run this command in the command line to create a fungible token, provided spl-token-cli is installed:
spl-token create-token
Token Metadata Program
The mint accounts contain certain data attributes such as the current token supply. However, they lack standardized data such as name and symbol. To solve this, Metaplex introduced the Token Metadata Program. This program allows additional data to be attached to fungible and non-fungible tokens using PDAs (Program Derived Addresses) derived from the mint address.
The Token Metadata program was initially created to simplify creating NFTs on Solana. However, it also works with SFTs, which are semi-fungible tokens. SFTs combine the characteristics of both fungible and non-fungible tokens. They behave like fungible tokens initially, meaning they can be exchanged with identical tokens without losing value for either party. After being used, they lose their exchange value and gain the attributes of collectible non-fungible tokens. SFTs operate as a unique type of account to which metadata is attached to represent characteristics in a game or metaverse environment. SFTs are preferred over NFTs in certain contexts due to their efficiency, cost-effectiveness, flexibility, and improved transaction security.
The Token Metadata program also supports Programmable NFTs (pNFTs). This new asset standard allows creators to define custom rules on specific operations and delegate more granularly to third-party authorities. The pNFT's token account is always frozen on the SPL token program, regardless of whether the pNFT is delegated. This ensures that no one can bypass the Token Metadata program by interacting with the SPL Token program directly.
Monitor New Tokens
To monitor newly minted Tokens, we’ll set up a webhook. Webhooks allow you to listen to on-chain events and trigger specific actions when these events occur. We’ll configure our webhook to listen to the TOKEN_MINT transaction type from the Token Metadata Program. The sources currently supported for this transaction type are (other sources will be tagged as “UNKNOWN”):
"TOKEN_MINT": [ "CANDY_MACHINE_V1", "ATADIA", "SOLANA_PROGRAM_LIBRARY" ]
Webhooks can be created using the Helius Dashboard, or be coded using the API reference. To create one via the Dashboard, go to the Webhooks section in the left panel and click New Webhook. Then, configure the webhook by providing details such as:
- Network: Mainnet/Devnet
- Webhook Type: You can select either Enhanced/Raw/Discord. If you choose Discord, you must submit the Webhook URL, and your notification will be formatted and sent directly by the bot. You can refer to the steps to get the Webhook URL for a Discord bot here. If you select Raw, you won’t be able to specify the transaction type.
- Transaction Type: Select TOKEN_MINT to listen to newly minted tokens. You can find other transaction types supported by a Program here.
- Webhook URL: Add the endpoint that will listen to the notifications (e.g., Discord Bot, Website, etc.)
- Authentication Header: Enter an authentication header to pass the POST requests to your webhook. Note that this is optional.
- Account Address: Add Token Metadata Program Address here: metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s. For other cases, you can add more than one account address if required. You can include their address if you wish to hear from a particular user in the transaction.
Once confirmed, your webhook is ready to use, and you can build the appropriate frontend based on your Webhook URL. Here, we selected Discord as the Webhook Type and provided the Webhook URL of a Discord bot, so we don’t need to code the Discord Bot. We will receive notifications like this:
Retrieve Token Metadata
You can use the token ID (mint address of the token) to obtain metadata of a particular token. Parse the JSON notification sent via Enhanced webhook (when the webhook type is set to Enhanced). The Mint Address can be found in the "mint" field within the first object of the transferTokens array. Once you have the token ID, you can use the getAsset method provided by the DAS API to retrieve additional information about the token.
For instance, you can use the getAsset method to obtain information about Jito Staked SOL (JitoSOL):
const url = `https://mainnet.helius-rpc.com/?api-key=<api_key>`
const getAsset = async () => {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 'my-id',
method: 'getAsset',
params: {
id: 'J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn',
displayOptions: {
showFungible: true //return details about a fungible token
}
},
}),
});
const { result } = await response.json();
console.log("Asset: ", result);
};
getAsset();
You can find more examples and a complete schema for the request and response of this method in our documentation.
Conclusion
In this article, we learned how tokens are created on Solana, what SPL tokens are, and how to monitor new tokens by setting up a webhook and fetching their metadata via Helius. If you need any help or support, don't hesitate to contact us on Discord!
Be sure to enter your email address below so you’ll never miss an update about what’s new on Solana. Ready to dive deeper? Explore the latest articles on the Helius blog and continue your Solana journey, today.