SolRengine Tokens

SPL token metadata and portfolio for Rails. Persists token metadata (name, symbol, icon) in your database via Jupiter API. Caches USD prices. Assembles wallet portfolios.

Part of the SolRengine framework.

Install

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

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 owned by the wallet, via the Metaplex DAS API:

portfolio.nfts  # => [{ id:, name: "Mad Lad #1234", image: "https://...", collection: "...", compressed: false }, ...]

Note: Portfolio#nfts uses the DAS getAssetsByOwner method, which requires a DAS-capable RPC endpoint (Helius, Triton, ...). The public api.*.solana.com endpoints do not serve DAS — on those, 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