Repository navigation
Getting Started
This page covers the smallest useful integration with the Free DefiLlama API. No API key is required for the operations used here. For Pro configuration and access, continue with Authentication and Configuration.1
The module targets Go 1.22 and newer. Add the current release to an application with:
go get github.com/tigusigalpa/defillama-goImport the package with an explicit alias when desired:
import defillama "github.com/tigusigalpa/defillama-go"Create one Client during application setup, then pass a request-scoped context to each API call. The following example retrieves the protocol list and guards both construction and the network request.
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
client, err := defillama.New(defillama.WithTimeout(10 * time.Second))
if err != nil {
return fmt.Errorf("create DefiLlama client: %w", err)
}
protocols, err := client.TVL().GetProtocols(ctx)
if err != nil {
return fmt.Errorf("list protocols: %w", err)
}
for _, protocol := range protocols[:min(3, len(protocols))] {
fmt.Printf("%s: $%.0f TVL\n", protocol.Name, protocol.TVL)
}New validates configuration but does not contact the network. A constructed client is safe to share between goroutines. The context passed to GetProtocols controls the request deadline and cancellation.1
The client organizes operations by data domain. An accessor returns a client-owned service value; applications normally retain the top-level Client, not individual service instances.
| Accessor | Typical first call | Data domain |
|---|---|---|
TVL() |
GetProtocols(ctx) |
Protocols, chains, TVL, and TVL metrics. |
Prices() |
GetCurrentPrices(ctx, coins) |
Current and historical token prices. |
Stablecoins() |
GetStablecoins(ctx, opts) |
Stablecoin supply, charts, and prices. |
Yields() |
GetPools(ctx) |
Free pool data and Pro earn/borrow data. |
Volumes() |
GetDEXOverview(ctx, opts) |
DEX, options, open-interest, and derivatives data. |
Fees() |
GetOverview(ctx, opts) |
Fee and revenue overview/summary data. |
Bridges() |
GetBridges(ctx, opts) |
Pro bridge records, volumes, and transactions. |
RWA() |
GetCurrentAssets(ctx) |
Pro real-world asset data. |
The remaining accessors—such as Ecosystem(), Treasury(), Equities(), and PreIPO()—are documented in Pro API. The full list is in API Reference.
Use the identifier expected by the underlying DefiLlama endpoint. The library path-escapes each path parameter and joins a slice of coin identifiers with commas. It does not translate human-friendly names to protocol slugs, token addresses, or chain identifiers.1
| Input | Expected form | Example |
|---|---|---|
| Protocol | DefiLlama protocol slug | aave |
| Chain | DefiLlama chain name | Ethereum |
| Token | chain:address |
ethereum:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 |
| CoinGecko asset | coingecko:id |
coingecko:bitcoin |
| Time | Unix timestamp in seconds | time.Now().UTC().Unix() |
For example, request a historical price at a fixed instant:
at := time.Date(2025, time.January, 1, 0, 0, 0, 0, time.UTC).Unix()
prices, err := client.Prices().GetHistoricalPrices(ctx,
[]string{"coingecko:ethereum"},
at,
)
if err != nil {
return err
}
fmt.Println(prices["coingecko:ethereum"].Price)After cloning the repository, run the checked Free API example from its root directory:
go run ./examples/basicThe example makes live API calls. The test suite does not: it uses local httptest servers and needs neither network access nor an API key.2
Use Protocols and TVL to explore the Free TVL endpoints, or Token Prices to retrieve token prices. Configure a key before calling a Pro-only method; otherwise the SDK returns *defillama.ProAPIKeyRequiredError locally, before building a request.1
defillama-go is an MIT-licensed Go client for the DefiLlama API. For endpoint semantics and API-plan details, consult the official DefiLlama API reference.