Skip to main content

Usage

const { 
  fetchWallet, 
  data, 
  isLoading, 
  error
} = useGetWallet();

Parameters

  • externalUserId (string): userId from your external provider
  • bearerToken (string): Bearer token for authentication

Return Value

Returns an object containing:
  • fetchWallet: Function to trigger token transfer
  • data: data containing the public key od the wallet as well as the encrypted private key.
  • isLoading: Boolean indicating if the operation is in progress
  • error: Any error that occurred during the process

Example Implementation

export function WalletPage(){
  const user = useUser();
  const { getToken } = useAuth();
  
  const { data: wallet, isLoading, error, fetchWallet } = useGetWallet({
    params: {
      externalUserId: user.user?.id || "",
    },
    getBearerToken: async () => {
      const token = await getToken();
      if (!token) throw new Error("No token found");
      return token;
    },
    queryOptions: {
      enabled: Boolean(user.user?.id),
    },
  });

  // Or use fetchWallet manually:
  const loadWallet = async () => {
    if (!user.user?.id) return;
    try {
      const token = await getToken();
      if (!token) throw new Error("No token found");
      
      const wallet = await fetchWallet({
        params: {
          externalUserId: user.user.id,
        },
        getBearerToken: async () => token,
      });
      
      console.log("Wallet loaded:", wallet);
    } catch (error) {
      console.error("Error loading wallet:", error);
    }
  };

  return (
    <div>
      {isLoading && <p>Loading wallet...</p>}
      {error && <p>Error: {error.message}</p>}
      {wallet && (
        <div>
          <p>Public Key: {wallet.publicKey}</p>
          <p>Normalized Public Key: {wallet.normalizedPublicKey}</p>
        </div>
      )}
    </div>
  );
}
Chipi never stores your decrypted sensitive data. All private keys and authentication tokens remain secure and are never accessible to Chipi servers.