Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,37 @@ const mintedNfd = await nfd
})
```

### Purchasing NFDs (Claiming & Buying)

```typescript
import { NfdClient } from '@txnlab/nfd-sdk'

const nfd = NfdClient.testNet()

// Get a purchase quote to check eligibility and pricing
const quote = await nfd
.setSigner(activeAddress, transactionSigner)
.getPurchaseQuote('reserved-nfd.algo')

if (quote.canClaim) {
// Claim a reserved NFD (automatically uses signer's address)
const claimedNfd = await nfd
.setSigner(activeAddress, transactionSigner)
.claim('reserved-nfd.algo')

console.log('Successfully claimed:', claimedNfd.name)
}

if (quote.canBuy) {
// Buy an NFD from the secondary market
const purchasedNfd = await nfd
.setSigner(activeAddress, transactionSigner)
.buy('forsale-nfd.algo')

console.log('Successfully purchased:', purchasedNfd.name)
}
```

### Managing an NFD

```typescript
Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This directory contains example applications demonstrating various features of t
- [API Search](./api-search/): Demonstrates how to use the API client to search for NFDs
- [Reverse Lookup](./reverse-lookup/): Demonstrates how to look up NFDs by wallet address
- [Mint](./mint/): Demonstrates how to mint NFDs
- [Claim NFD](./claim-nfd/): Demonstrates how to claim NFDs reserved for your wallet address
- [Link Address](./link-address/): Demonstrates how to link addresses to NFDs
- [Set Metadata](./set-metadata/): Demonstrates how to set metadata for NFDs
- [Set Primary NFD](./set-primary-nfd/): Demonstrates how to set a primary NFD for an address
Expand Down
24 changes: 24 additions & 0 deletions examples/claim-nfd/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
60 changes: 60 additions & 0 deletions examples/claim-nfd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# NFD Claim Example

This example demonstrates how to use the NFD SDK to claim NFDs that are reserved for your wallet address.

## Features

- Connect your wallet using the Wallet Connect protocol
- Search for NFDs reserved for your address using the NFD API
- Claim reserved NFDs using the NFD SDK's claiming API
- Simple and clean UI for managing the claiming process

## Getting Started

1. Install dependencies:

```bash
npm install
```

2. Start the development server:

```bash
npm run dev
```

3. Open your browser to the provided localhost URL

## How it Works

1. **Connect Wallet**: Use the wallet connection interface to connect your Algorand wallet
2. **Search Reserved NFDs**: The app automatically searches for NFDs reserved for your connected address
3. **Claim NFDs**: Click the "Claim" button next to any reserved NFD to claim it to your wallet

## Code Example

Here's how simple it is to claim an NFD with the new API:

```typescript
// Simple claiming - just connect wallet and call claim()
const claimedNfd = await nfd
.setSigner(address, transactionSigner)
.claim('reserved-nfd.algo')
```

The NFD SDK automatically uses your connected wallet address as the claimer, making the API clean and intuitive.

## Important Notes

- This example runs on Algorand TestNet
- You need TestNet ALGO in your wallet to pay for transaction fees
- Reserved NFDs may have a claiming cost (calculated based on the NFD's pricing), plus transaction fees
- Make sure your wallet is connected to TestNet

## Technology Stack

- **React**: Frontend framework
- **TypeScript**: Type safety
- **Vite**: Build tool and dev server
- **@txnlab/nfd-sdk**: NFD SDK for blockchain interactions
- **@txnlab/use-wallet-react**: Wallet connection management
42 changes: 42 additions & 0 deletions examples/claim-nfd/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import globals from 'globals'
import tseslint from 'typescript-eslint'
import baseConfig from '../../eslint.config.js'

export default tseslint.config(
...baseConfig,
{
files: ['src/**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
project: './tsconfig.json',
},
},
plugins: {
'@typescript-eslint': tseslint.plugin,
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
{
files: ['*.config.{js,ts}'],
languageOptions: {
parserOptions: {
project: './tsconfig.node.json',
},
},
plugins: {
'@typescript-eslint': tseslint.plugin,
},
},
)
13 changes: 13 additions & 0 deletions examples/claim-nfd/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>NFD Claim Example</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>
27 changes: 27 additions & 0 deletions examples/claim-nfd/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@txnlab/nfd-sdk-claim-example",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint \"**/*.{js,jsx,ts,tsx}\"",
"preview": "vite preview"
},
"dependencies": {
"@algorandfoundation/algokit-utils": "^8.2.2",
"@txnlab/nfd-sdk": "^0.8.0",
"@txnlab/use-wallet-react": "^4.0.0",
"algosdk": "^3.2.0",
"lute-connect": "^1.4.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.64",
"@types/react-dom": "^18.2.21",
"@vitejs/plugin-react": "^4.2.1",
"vite": "^4.5.2",
"vite-plugin-node-polyfills": "^0.23.0"
}
}
1 change: 1 addition & 0 deletions examples/claim-nfd/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading