Skip to main content

index/functions/getTokenAssetUrl.md

getTokenAssetUrl(tokenName, assetType, baseUrl, extension?): string

Get redirect URL for a generic token asset

Low-level utility for generating asset URLs when the specific helper functions don't meet your needs. Combines token name, asset type, and extension.

Parameters​

ParameterTypeDescription
tokenNamestringToken name (lowercase)
assetTypestringAsset type name (e.g., 'image', 'thumbnail', 'animated')
baseUrlstringAPI base URL
extension?stringOptional file extension (no default, must be provided if needed)

Returns​

string

Full redirect URL to asset

Throws​

Error if token name is invalid, asset type is empty, or extension format is incorrect

Example​

// Without extension
const imageUrl = getTokenAssetUrl('anime', 'image', 'https://api.example.com');
// → "https://api.example.com/v1/tokens/anime/assets/image"

// With extension
const thumbUrl = getTokenAssetUrl('anime', 'thumbnail', 'https://api.example.com', 'png');
// → "https://api.example.com/v1/tokens/anime/assets/thumbnail.png"

Since​

7.3.0