Exploring Solana: My Web3 Journey Day 14
Table of contents
- Solana vs. Bitcoin: A Quick Comparison
- Accounts and Rent on Solana
- Setting Up Solana CLI and Wallet Creation
- Token Minting and Verifying On-Chain
- Creating an Associated Token Account and Minting Tokens
- Importing Tokens into Phantom Wallet
- Writing Equivalent Code in JavaScript, Rust, Python, and Go
- Final Thoughts: Overcoming Challenges
Today was an exciting and challenging day in my Web3 journey as I explored Solana’s blockchain ecosystem. From creating tokens to understanding Solana’s unique architecture, I faced some interesting obstacles but found solutions that deepened my understanding of blockchain technology. Here’s a breakdown of what I learned, the challenges I encountered, and how I overcame them.
Solana vs. Bitcoin: A Quick Comparison
Solana and Bitcoin take fundamentally different approaches to blockchain. Solana’s Proof of History (PoH) consensus is built for speed and scalability, while Bitcoin’s Proof of Work (PoW) focuses on security and decentralization. This distinction is crucial for understanding why Solana is better suited for high-throughput applications like DeFi and NFTs.
Accounts and Rent on Solana
One of the unique features of Solana is the rent mechanism. Each account on the network must maintain a minimum balance (rent) to stay active. This ensures that dormant accounts don’t waste network resources. It’s a clever way to manage blockchain bloat, but it initially confused me, especially since I was coming from a Bitcoin background where this concept doesn’t exist.
Challenge: Understanding rent and ensuring my accounts had enough balance to stay active.
Solution: After reading the Solana documentation, I discovered that Solana offers a rent exemption for accounts with sufficient balance. I used this exemption to ensure my accounts wouldn’t be deactivated. You can use the following command to check your account's rent status:
bashCopy codesolana account <account_address>
Setting Up Solana CLI and Wallet Creation
To start experimenting with Solana, I had to install the Solana CLI and set up a wallet. The process was straightforward, but I hit a snag during the airdrop step.
Installed Solana CLI.
Created a CLI wallet.
Set the RPC URL to the devnet.
Airdropped some SOL into my wallet to interact with the blockchain.
Checked my balance to ensure everything was working properly.
bashCopy codesolana airdrop 2 <wallet_address>
Challenge: The first time I tried to airdrop SOL, I got a connection timeout error.
Solution: I realized this was due to the RPC node being overloaded. To fix it, I switched to a different RPC URL using the command:
bashCopy codesolana config set --url https://api.devnet.solana.com
This worked, and I was able to successfully airdrop SOL and check my balance.
Token Minting and Verifying On-Chain
Creating a token was one of the most exciting parts of the day. Solana’s Token 22 program simplifies the process of creating, minting, and verifying tokens. Here’s a summary of what I did:
Created a token mint using the CLI.
Verified the token mint on-chain.
Checked the supply of the token to confirm the minting process.
bashCopy codespl-token create-token
spl-token mint <token_address> <amount>
Challenge: While minting tokens, I mistakenly created multiple token accounts, which led to confusion in tracking the balances.
Solution: I realized that each token mint should be tied to a single associated token account. By consolidating the token accounts and keeping track of the correct token mint address, I could avoid duplicate accounts. Here’s the command to create an associated token account:
bashCopy codespl-token create-account <token_address>
Creating an Associated Token Account and Minting Tokens
After creating the token mint, I set up an associated token account and minted tokens. Using the Solana Explorer, I verified the balances in my wallet.
Challenge: I encountered issues when minting tokens to my account—the tokens weren’t showing up in my balance.
Solution: I discovered that I had to manually refresh the Explorer after minting to see the updated balance. Also, I had to make sure that I was minting tokens to the correct associated token account.
bashCopy codespl-token mint <token_address> <amount> <wallet_address>
Importing Tokens into Phantom Wallet
Once I minted the tokens, I imported them into the Phantom wallet to visualize the balances. It was satisfying to see my custom token in the wallet interface.
Challenge: Initially, the Phantom wallet didn’t display the tokens I had minted.
Solution: I had to manually add the token using its token address. Once I did this, the token appeared in the wallet, and I could see my balance.
Writing Equivalent Code in JavaScript, Rust, Python, and Go
To deepen my understanding, I wrote equivalent code in JavaScript to interact with the Solana blockchain. Here’s an example of how I airdropped SOL using JavaScript:
javascriptCopy codeconst solanaWeb3 = require('@solana/web3.js');
const connection = new solanaWeb3.Connection(solanaWeb3.clusterApiUrl('devnet'));
const wallet = solanaWeb3.Keypair.generate();
// Airdrop 1 SOL
connection.requestAirdrop(wallet.publicKey, solanaWeb3.LAMPORTS_PER_SOL);
// Check balance
connection.getBalance(wallet.publicKey).then(balance => {
console.log(`Wallet balance: ${balance / solanaWeb3.LAMPORTS_PER_SOL} SOL`);
});
I also explored writing similar functionality in Rust, Python, and Go, which helped me appreciate the flexibility of Solana’s API across different languages.
Final Thoughts: Overcoming Challenges
Day 14 presented several challenges, from understanding Solana’s rent system to troubleshooting token minting and wallet connectivity. Each issue forced me to dig deeper into Solana’s documentation and learn the nuances of interacting with a blockchain. Solana’s ecosystem is powerful but can be tricky, especially for beginners. However, with patience and problem-solving, I was able to navigate through and successfully create my first token.
Stay tuned for more as I continue to explore Solana and broader Web3 concepts!
Key Takeaways:
Solana’s rent system and token creation tools are powerful but require careful management.
Using the CLI and RPC URLs can lead to occasional connectivity issues, but there are workarounds.
Writing equivalent code in multiple languages builds a deeper understanding of blockchain APIs.
Let’s continue learning and building in Web3!
Subscribe to my newsletter
Read articles from Harsh Kumar Rai directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Harsh Kumar Rai
Harsh Kumar Rai
I am a passionate IT student at the Army Institute of Technology, Pune, with a strong foundation in competitive programming and a keen interest in emerging technologies. My expertise spans across various domains, including: Specialist at Codeforces , 4* Star on CodeChef, and 2333 rank in Google Code Jam.Proficient in MERN stackctively exploring Web3 technologies, As I continue to expand my expertise in Web3, I am dedicated to learning in public and sharing my journey through LinkedIn and Twitter