This project is based on the guide, How to Get All Tokens Held by a Wallet in Solana by Aaron Milano.
To begin, clone the qn-guide-examples repo and navigate to this project's directory.
git clone https://github.com/quiknode-labs/qn-guide-examples.git
cd qn-guide-examples/solana/sol-get-tokenscp .env.example .envEither npm or pnpm can be used to install the project's dependencies and run the script.
npm i
npm startpnpm i
pnpm startIf used with the example wallet provided (vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg) the result will look like the following:
Found 55 token account(s) for wallet vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg.
Token Account No. 1: 5yXaDYUKMvWGcgaUp5G99KizoU2dacAWGBupReC98RkZ
--Token Mint: 34wykniHzkMCW2yjfhKWaTV5rMW6LzY4UGJUV4FNUGJa
--Token Balance: 100
Token Account No. 2: GsufVXTZfr14Pde63ggD75utapmWmHUWnYZkb9kfjN3u
--Token Mint: 559u4Tdr9umKwft3yHMsnAxohhzkFnUBPAFtibwuZD9z
--Token Balance: 1
...