Getting Started with TON Blockchain

·

Build your first application on the TON blockchain from scratch and explore its fundamentals—speed, reliability, and the core concepts of asynchronous thinking.

Beginner-Friendly Guide

If you're new to programming, this guide is the perfect starting point.

This learning path consists of 5 modules and takes approximately 45 minutes.

🛳 What You’ll Learn

In this tutorial, you’ll learn how to perform blockchain transactions effortlessly using JavaScript. While you could learn without completing this guide, this method is both convenient and beginner-friendly.

  1. Create a TON Wallet – Use Tonkeeper to set up your own wallet.
  2. Fund Your Wallet – Use a Testnet faucet to receive test tokens.
  3. Understand Smart Contracts – Learn key TON concepts (Addresses, Cells).
  4. Interact with TON – Use the TypeScript SDK and API providers.
  5. Compile Your First Transaction – Deploy an NFT Miner console application.

You're about to mine an NFT rocket achievement!

As one of TON’s first miners, you’ll use a Proof-of-Work smart contract to uncover secret rewards for your TON wallet.

Our goal? Mine an NFT! This achievement will remain with you _forever_.

Even on the mainnet, mining this NFT costs just 0.05 TON!

Mining on the TON Blockchain

Today, we’ll teach aspiring builders how to mine on the TON blockchain. This experience will help you understand mining’s significance and how Bitcoin mining revolutionized the industry.

The PoW Giver smart contract framework laid the groundwork for TON’s initial mining phase. Although the framework was finalized upon release, the last TON was mined in June 2022, concluding TON’s Proof-of-Work (PoW) token distribution. Now, TON has transitioned to Proof-of-Stake (PoS).

👉 Explore TON’s Economic Model & Mining

Now, let's focus on becoming a TON developer and learning how to mine NFTs!

🦄 Getting Started

To begin, developers will need the following:

Download & Create a Wallet

First, you need a wallet to receive and store TON. Here’s how:

  1. Install Tonkeeper on your smartphone (Download here).
  2. Enable Testnet mode (Follow this guide).

Now, let’s start developing!

Project Setup

To simplify development, we’ll use a template:

  1. Log in to GitHub.
  2. Use the ton-onboarding-challenge template to create your repository (Click "Use this template").

Congrats! You now have a high-performance repository serving as your miner’s core.

Development Environment

Choose between local or cloud-based development:

Cloud Codespace

Local Development

Requires:

Clone the repository and open it in your IDE.

Running Scripts

Execute TypeScript scripts via the terminal:

npm run start:script  

🎯 Connecting to TON

To interact with the TON blockchain, you’ll need:

Smart Contract Address

  1. Wallet Address – Your Tonkeeper Testnet wallet.
  2. Collection Address – The NFT mining smart contract (Getgems).

Parsing Addresses

Use Address.parse() to convert addresses:

const walletAddress = Address.parse('YOUR_WALLET_ADDRESS');  
const collectionAddress = Address.parse('COLLECTION_ADDRESS');  

Connecting to an API Provider

Use the TONCenter API (https://testnet.toncenter.com/api/v2/jsonRPC):

const client = new TonClient({ endpoint: "https://testnet.toncenter.com/api/v2/jsonRPC" });  

Retrieving Mining Data

Run get_mining_data to fetch mining parameters:

const miningData = await client.runMethod(collectionAddress, 'get_mining_data');  

The response includes:

🛠 Building an NFT Miner

Preparing the Mining Message

Follow the Proof-of-Work Cell layout:

const mineParams: MineMessageParams = {  
  expire: unixNow() + 300, // 5-min expiry  
  mintTo: walletAddress,  
  data1: 0n, // Incremented during mining  
  seed  
};  

let msg = Queries.mine(mineParams);  

Mining Process

Find a hash lower than complexity:

while (bufferToBigInt(msg.hash()) > complexity) {  
  mineParams.data1 += 1n;  
  msg = Queries.mine(mineParams);  
}  

Sending the Transaction

Use Blueprint to send the transaction:

await provider.sender().send({  
  to: collectionAddress,  
  value: toNano(0.05), // 0.05 TON  
  body: msg  
});  

Run the script:

npm start  

Scan the QR code with Tonkeeper and confirm the transaction.

⛏ Mining Your NFT

Testnet Mining

  1. Enable Testnet mode in Tonkeeper.
  2. Replace walletAddress and collectionAddress with Testnet values.
  3. Run the miner (npm start).

👉 View Your NFT in Tonkeeper

Mainnet Mining

  1. Use Mainnet mode in Tonkeeper.
  2. Update endpoint to https://toncenter.com/api/v2/jsonRPC.
  3. Replace addresses with Mainnet equivalents.

🧙 What’s Next?

Explore further:

Got feedback? Contact @SwiftAdviser. Happy building! 🚀