Function Signature

function searchFile(
  file: File,
  walletAddress?: string
): Promise<Response>;
file
File
required
The file to search for.
walletAddress
string
Optional wallet address to filter search results to specific registrations.
Promise
Promise<[Response](/sdk-reference/types#searchfile-response)>
A promise that resolves with the response from searching for a file.
Search Modes:
  • File only: Returns all registrations for this file hash
  • File + Wallet: Returns specific registration by this wallet for this file hash
Type Definitions: For detailed type information, visit the Types page.

Usage

import { TrustEngineSDK } from '@trust-engine/sdk';
import { useState } from 'react';

const sdk = new TrustEngineSDK();

export default function FileSearch() {
  const [file, setFile] = useState<File | null>(null);
  const [isSearching, setIsSearching] = useState(false);
  const [result, setResult] = useState<any | null>(null);

  const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
    if (e.target.files) {
      setFile(e.target.files[0]);
    }
  };

  const handleSearch = async () => {
    if (!file) return;
    setIsSearching(true);
    try {
      // Search all registrations for this file
      const searchResult = await sdk.searchFile({ file });
      
      // Or search for specific wallet's registration:
      // const searchResult = await sdk.searchFile({ file, 'specific-wallet-address' });
      
      setResult(searchResult);
    } catch (error) {
      console.error('❌ Search failed:', error.message);
      setResult({ error: error.message });
    } finally {
      setIsSearching(false);
    }
  };

  return (
    <div>
      <input type="file" onChange={handleFileChange} />
      <button onClick={handleSearch} disabled={!file || isSearching}>
        {isSearching ? 'Searching...' : 'Search for File'}
      </button>
      {result && <pre>{JSON.stringify(result, null, 2)}</pre>}
    </div>
  );
}