Skip to contents

Inserts or updates the OpenSea NFT URL for an artwork. Use this when an artist wants to link their artwork to an NFT listing on OpenSea. The function parses the OpenSea URL to extract chain, contract, and token ID, then stores the full record.

Usage

.upsert_nft_url(url, artist, artwork, has_nft, cn = NULL)

Arguments

url

Character. The OpenSea NFT URL (e.g., `"https://opensea.io/assets/ethereum/0x.../123"`). If `NULL` or empty string, the function returns early without making changes.

artist

Character. Artist UUID.

artwork

Character. Artwork UUID.

has_nft

Logical. If `TRUE`, updates existing record in `app.artwork_opensea`. If `FALSE`, inserts new record and sets `is_nft = TRUE` in `app.artwork_index`.

cn

Database connection. If `NULL`, opens and closes automatically.

Value

`invisible(NULL)`. Called for side effects (database writes).

Details

This function performs two different operations based on `has_nft`:

**When `has_nft = TRUE` (UPDATE):** - Updates all fields in existing `app.artwork_opensea` record - Refreshes `modified_utc` timestamp

**When `has_nft = FALSE` (INSERT):** - Builds row via [.build_opensea_row()] with parsed URL data - Inserts new row into `app.artwork_opensea` - Sets `is_nft = TRUE` in `app.artwork_index`

The OpenSea URL is parsed by [artopensea::parseOpenseaURL()] to extract chain, contract address, and token ID. Artist account info is fetched via [artutils::get_artist_opensea()].

The `has_nft` flag should come from `app.artwork_index.is_nft` to ensure consistency.

See also

* [.upsert_print_url()] for print store links * [.build_opensea_row()] for row construction * [artopensea::parseOpenseaURL()] for URL parsing

Examples

if (FALSE) { # \dontrun{
# Update existing NFT URL
.upsert_nft_url(
  url = "https://opensea.io/assets/ethereum/0xabcd.../42",
  artist = "746b8207-72f5-4ab6-8d19-a91d03daec3d",
  artwork = "99a61148-1d3b-4340-8cf6-92ad26046b0f",
  has_nft = TRUE
)

# Add new NFT URL (artwork not yet NFT-enabled)
.upsert_nft_url(
  url = "https://opensea.io/assets/matic/0xdef.../7",
  artist = artist_uuid,
  artwork = artwork_uuid,
  has_nft = FALSE
)
} # }