solrengine-tokens
SPL token metadata, wallet portfolios, and NFTs for Rails. Persists token metadata via Jupiter, caches USD prices, and reads Metaplex NFTs via the DAS API.
SPL token metadata and portfolio for Rails. Persists token metadata (name, symbol, icon) in your database via the Jupiter API, caches USD prices, and assembles wallet portfolios.
Install
# Gemfile
gem "solrengine-tokens"
rails generate solrengine:tokens:install
rails db:prepare
Configuration
A Jupiter API key is required (free tier available):
# config/initializers/solrengine_tokens.rb
Solrengine::Tokens.jupiter_api_key = ENV["JUPITER_API_KEY"]
If your token model is named something other than Token:
Solrengine::Tokens.token_class_name = "SplToken"
Usage
Build a wallet portfolio:
portfolio = Solrengine::Tokens::Portfolio.new("Abc...xyz")
portfolio.tokens # => [{ symbol: "SOL", ui_amount: 2.5, usd_value: 234.50 }, ...]
portfolio.total_usd_value # => 1847.63
portfolio.recent_transactions # => [{ signature:, block_time:, ... }]
NFTs
Since 0.2.0, the portfolio also reads the wallet’s NFTs — regular NFTs, Metaplex Core assets, and compressed cNFTs — via the Metaplex DAS API:
portfolio.nfts
# => [{ id: "F3Kd...", name: "SMB Gen3 #14822", image: "https://...",
# collection: "8Rt3...", compressed: false }, ...]
Results are cached for 60 seconds, and the entries are plain hashes ready to render — see the WalletTrain dashboard for a real integration.
Note:
Portfolio#nftscalls the DASgetAssetsByOwnermethod, which needs a DAS-capable RPC endpoint (Helius, Triton, …). The publicapi.*.solana.comendpoints don’t serve DAS — there, the call degrades to an empty list.
Token metadata is fetched once from Jupiter and persisted:
Token.find_or_fetch("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v")
# => #<Token mint: "EPjF...", name: "USD Coin", symbol: "USDC", icon: "https://...">
Batch lookup for multiple mints:
Token.find_or_fetch_many([
"So11111111111111111111111111111111111111112",
"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
])
# => { "So11..." => #<Token>, "EPjF..." => #<Token> }
License
MIT