Skip to main content

Token Ownership Workers

Two workers for managing NFT/token ownership: one for refreshing tokens and one for external ownership updates.

Installation

import '@unchainedshop/plugins/worker/update-token-ownership';

Workers Included

This file registers two workers:

1. Refresh Tokens Worker

Automatically finds all tokens and accounts, then triggers ownership updates.

PropertyValue
Keyshop.unchained.worker-plugin.refresh-tokens
TypeREFRESH_TOKENS
Auto-ScheduleEvery minute

2. Update Token Ownership Worker (External)

External worker placeholder for the actual ownership verification process.

PropertyValue
Keyshop.unchained.worker-plugin.update-token-ownership
TypeUPDATE_TOKEN_OWNERSHIP
Externaltrue

How It Works

Refresh Tokens Flow

  1. Auto-scheduled every minute
  2. Collects tokens: Finds all tokens with wallet addresses
  3. Collects accounts: Finds all users with verified Web3 addresses
  4. Creates work: Triggers UPDATE_TOKEN_OWNERSHIP with the token and account data
  5. External processing: An external system processes the ownership verification

External Update Flow

  1. External system receives UPDATE_TOKEN_OWNERSHIP work
  2. Verifies token ownership on the blockchain
  3. Marks work as complete via GraphQL

Manual Trigger

Refresh All Tokens

mutation RefreshAllTokens {
createWork(type: "REFRESH_TOKENS") {
_id
status
}
}

Update Specific Tokens (External)

mutation UpdateOwnership {
createWork(
type: "UPDATE_TOKEN_OWNERSHIP"
input: {
filter: {
tokens: [{ _id: "token-1" }, { _id: "token-2" }],
accounts: ["0xAddress1", "0xAddress2"]
}
}
) {
_id
status
}
}

Result

Refresh Tokens

{
"forked": "update-token-ownership-work-id"
}

Input for UPDATE_TOKEN_OWNERSHIP

ParameterTypeDescription
filter.tokensArrayToken objects to check ownership for
filter.accountsArrayWallet addresses to verify

Adapter Details

REFRESH_TOKENS

PropertyValue
Keyshop.unchained.worker-plugin.refresh-tokens
TypeREFRESH_TOKENS
Auto-ScheduleEvery minute
Retries0

UPDATE_TOKEN_OWNERSHIP

PropertyValue
Keyshop.unchained.worker-plugin.update-token-ownership
TypeUPDATE_TOKEN_OWNERSHIP
Externaltrue

Source

worker/update-token-ownership.ts