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 [walletId, setWalletId] = useState("");
  const user = useUser();
  const { getToken } = useAuth();
  const getWallet = async () => {
    if (!user.user?.id) return;
    try {
      const newToken = await getToken();
     
      if (!newToken) {
        throw new Error("No token found");
      }
      const wallet = await fetchWallet({
        params: {
          externalUserId: user.user.id,
        },
        getBearerToken: async () => newToken,
      });
   
      setWalletId(wallet?.publicKey || "");
      if (!wallet.publicKey) {
        throw new Error("No wallet found");
      }
      setWalletId(wallet.publicKey);

      if (!newToken) {
        throw new Error("API public key is not set");
      }

    } catch (error) {
      console.error(error);
      return null;
    }
  };

}                      
Chipi never stores your decrypted sensitive data. All private keys and authentication tokens remain secure and are never accessible to Chipi servers.