Function Signature

function registerFile(
  options: Options
): Promise<Response>;
options
[Options](/sdk-reference/types#registerfile-options)
The options for registering a file.
Promise
Promise<[Response](/sdk-reference/types#registerfile-response)>
A promise that resolves with the response from registering a file.
Type Definitions: For detailed type information including all properties and their descriptions, visit the Types page.

Usage

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

const sdk = new TrustEngineSDK();

export default function FileRegistrar() {
  const [file, setFile] = useState<File | null>(null);
  const [isRegistering, setIsRegistering] = 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 handleRegister = async () => {
    if (!file) return;
    setIsRegistering(true);
    try {
      // Option 1: Managed wallets (automatic signing)
      const registrationResult = await sdk.registerFile({
        file,
        contentTitle: "My Awesome Document",
        walletAddress: "YourWalletAddressGoesHere",
        walletType: "managed"
      });
      
      // Option 2: Self wallets with action link (recommended)
      // const registrationResult = await sdk.registerFile({
      //   file,
      //   contentTitle: "My Awesome Document", 
      //   walletAddress: "YourWalletAddressGoesHere",
      //   walletType: "self",
      //   returnActionLink: true
      // });
      
      setResult(registrationResult);
    } catch (error) {
      console.error('❌ Registration failed:', error.message);
    } finally {
      setIsRegistering(false);
    }
  };

  return (
    <div>
      <input type="file" onChange={handleFileChange} />
      <button onClick={handleRegister} disabled={!file || isRegistering}>
        {isRegistering ? 'Registering...' : 'Register File'}
      </button>
      {result && (
        <div>
          <pre>{JSON.stringify(result, null, 2)}</pre>
          {result.details?.actionLink && (
            <p>
              <a href={result.details.actionLink} target="_blank" rel="noopener noreferrer">
                Open Action Link to Sign Transaction
              </a>
            </p>
          )}
        </div>
      )}
    </div>
  );
}

Wallet Types and Response Patterns

The registerFile function behaves differently based on the walletType and returnActionLink parameters:

Managed Wallets

When using walletType: "managed", transactions are automatically signed and submitted. The response includes a confirmed transaction:
{
  message: "✅ Success! Your file has been registered and confirmed on-chain.",
  details: {
    status: "confirmed",
    transactionSignature: "...",
    contentRegistrationPDA: "...",
    contentHash: "...",
    ipfsCid: "...",
    explorerUrl: "..."
  }
}
When using walletType: "self" with returnActionLink: true, you receive a secure web page link for transaction signing:
{
  message: "Transaction prepared and action link created. Use the link to sign the transaction.",
  details: {
    status: "action-link-created",
    actionLink: "http://trustengine.org/tx-action/abc123def456789",
    token: "abc123def456789", 
    expiresAt: "2024-01-25T15:30:00.000Z",
    contentHash: "..."
  }
}
Users can visit the actionLink to sign the transaction with their wallet (Phantom, Solflare, etc.) in a secure browser environment. When using walletType: "self" without returnActionLink (or returnActionLink: false), you receive the raw unsigned transaction:
{
  message: "Transaction prepared and pre-signed. Please sign and submit via your wallet.",
  details: {
    status: "requires-client-signature",
    transaction: "eJzTYmBkYGBkZWBgZGZgYGRhYGBkZmBgZGVgYGRmYGBkZWBgZGZgYGRh...",
    ipfsCid: "...",
    contentRegistrationPDA: "...",
    contentHash: "..."
  }
}
You’ll need to handle transaction signing and submission manually using the /transactions endpoint or the submitTransaction SDK method.