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.
| Property | Value |
|---|---|
| Key | shop.unchained.worker-plugin.refresh-tokens |
| Type | REFRESH_TOKENS |
| Auto-Schedule | Every minute |
2. Update Token Ownership Worker (External)
External worker placeholder for the actual ownership verification process.
| Property | Value |
|---|---|
| Key | shop.unchained.worker-plugin.update-token-ownership |
| Type | UPDATE_TOKEN_OWNERSHIP |
| External | true |
How It Works
Refresh Tokens Flow
- Auto-scheduled every minute
- Collects tokens: Finds all tokens with wallet addresses
- Collects accounts: Finds all users with verified Web3 addresses
- Creates work: Triggers
UPDATE_TOKEN_OWNERSHIPwith the token and account data - External processing: An external system processes the ownership verification
External Update Flow
- External system receives
UPDATE_TOKEN_OWNERSHIPwork - Verifies token ownership on the blockchain
- 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
| Parameter | Type | Description |
|---|---|---|
filter.tokens | Array | Token objects to check ownership for |
filter.accounts | Array | Wallet addresses to verify |
Adapter Details
REFRESH_TOKENS
| Property | Value |
|---|---|
| Key | shop.unchained.worker-plugin.refresh-tokens |
| Type | REFRESH_TOKENS |
| Auto-Schedule | Every minute |
| Retries | 0 |
UPDATE_TOKEN_OWNERSHIP
| Property | Value |
|---|---|
| Key | shop.unchained.worker-plugin.update-token-ownership |
| Type | UPDATE_TOKEN_OWNERSHIP |
| External | true |
Source
worker/update-token-ownership.ts