NFT Transaction Viewer
This React application displays the latest transfer transaction for a specified NFT address using the TONX SDK. Refer to this sample project's GitHub repository.
Environment Setup
- Install pnpm globally:
npm install -g pnpm
- Install project dependencies:
pnpm install
- Create a
.env
file in the root directory:
VITE_TONXAPI_KEY=your_testnet_api_key_here
Important Configuration Notes
Network Configuration
- The application is configured for testnet use. Make sure to use the correct network setting:
const client = new TONXJsonRpcProvider({
network: "testnet", // Keep this as testnet for development
apiKey: import.meta.env.VITE_TONXAPI_KEY,
});
NFT Address Configuration
The application uses a default NFT address for tracking:
const nftAddress = "EQAc4jcphnAeLQ_wmS7e4leWghFysRI_VKUCR0jhiVDX9hXn";
To track a different NFT:
- Replace the
nftAddress
constant with your desired NFT address - Ensure the address is valid and exists on the testnet
API Key Setup
- Get your API key from dashboard.tonxapi.com
- Important: Use a testnet API key
- Save it in your
.env
file as shown above
TypeScript Interfaces
The application uses TypeScript for type safety. Key interfaces include:
interface Transaction {
transaction_hash?: string;
[key: string]: unknown;
}
Running the Application
- Ensure your environment variables are set up:
cp .env.example .env
# Edit .env with your actual testnet API key
- Start the development server:
pnpm dev
- Open your browser and navigate to the local development server (usually
http://localhost:4000
)
Features
- View the latest transfer transaction for a specified NFT
- Direct link to transaction details on TON Explorer
- Loading state handling
- Error state handling
Transaction Viewing
The application provides two ways to view transaction information:
- Direct hash display for non-clickable transactions
- Clickable links to TON Explorer for valid transaction hashes
Error Handling
The application handles several states:
- "No connection" - Initial state
- "Error fetching transaction" - When API calls fail
- "No transaction found" - When no transfers are found
- Valid transaction hash - Displays with link to explorer
Security Best Practices
- Never commit API keys to version control
- Always use environment variables for sensitive data
- Validate NFT addresses before querying
- Handle API errors gracefully
Common Issues and Troubleshooting
-
API Key Issues
- Verify you're using a testnet API key
- Check if the API key is properly set in your .env file
- Ensure the environment variable is correctly accessed
-
No Transactions Found
- Verify the NFT address is correct
- Check if the NFT has any transfer history
- Ensure you're connected to the correct network (testnet)