Helper functions for parsing OpenSea URLs and integrating OpenSea badges into Shiny applications. Use these utilities to convert between OpenSea marketplace URLs and their component parts (chain, contract, token ID), or to add official OpenSea branding to your NFT displays.
These functions are particularly useful when: - Building Shiny NFT galleries that link to OpenSea marketplace - Processing user-provided OpenSea URLs to extract NFT identifiers - Generating marketplace links from database-stored NFT metadata
Usage
getOpenseaBadge(contract, id, chain, width = "120px")
parseOpenseaURL(nft_url)
buildOpenseaURL(chain, contract, id)Arguments
- contract
Character. NFT smart contract address in hexadecimal format (e.g., `"0x6444522C5aD44285b7856dd3336D09Fb939865F1"`). See `opensea-api` documentation for details on obtaining contract addresses.
- id
Character or Integer. NFT token ID within the contract. See `opensea-api` documentation for details on token IDs.
- chain
Character. Blockchain network identifier (e.g., `"matic"`, `"ethereum"`). See `opensea-api` documentation for supported chains.
- width
Character. CSS width specification for the badge image (default: `"120px"`). Accepts any valid CSS width value like `"150px"`, `"10em"`, or `"100 in your Shiny UI.
- nft_url
Character. Full OpenSea NFT URL in the format `https://opensea.io/assets/{chain}/{contract}/{id}`. Copy from browser address bar when viewing an NFT on OpenSea, or construct programmatically using `buildOpenseaURL()`.
Value
shiny.tag object. An HTML anchor (`<a>`) element containing the official OpenSea badge image. The badge links to the NFT's OpenSea marketplace page and opens in a new tab. Render this in Shiny UI functions like `uiOutput()` or `renderUI()`. The badge includes hover effects and shadow styling for professional appearance.
Named list with three character elements: `chain` (blockchain network), `contract` (NFT contract address), and `id` (token ID). Extract these components to pass to API functions like `get_os_nft()`. Use this when processing user input or scraping OpenSea URLs from external sources.
Character. Complete OpenSea marketplace URL for the specified NFT. Use this URL to create hyperlinks in Shiny apps, emails, or documentation. The URL format is `https://opensea.io/assets/{chain}/{contract}/{id}` and will open the NFT's detail page on OpenSea when clicked.
Functions
getOpenseaBadge(): Generate OpenSea badge widget for Shiny appsparseOpenseaURL(): Parse OpenSea NFT URL into componentsbuildOpenseaURL(): Build OpenSea NFT URL from components
Examples
if (FALSE) { # \dontrun{
getOpenseaBadge(
contract = "0x6444522C5aD44285b7856dd3336D09Fb939865F1",
id = 2,
chain = "matic"
)
} # }
parseOpenseaURL("https://opensea.io/assets/matic/0x644452.../2")
#> $chain
#> [1] "matic"
#>
#> $contract
#> [1] "0x644452..."
#>
#> $id
#> [1] "2"
#>
buildOpenseaURL("matic", "0x6444522C5aD44285b7856dd3336D09Fb939865F1", 2)
#> [1] "https://opensea.io/assets/matic/0x6444522C5aD44285b7856dd3336D09Fb939865F1/2"
