Skip to main content

getStarknetAccount

Retrieves a Starknet WalletAccount instance from a wallet account, allowing you to interact with the Starknet blockchain.

Usage

import { getStarknetAccount, isStarknetWalletAccount } from "@dynamic-labs-sdk/starknet";
import { getPrimaryWalletAccount } from "@dynamic-labs-sdk/client";

const walletAccount = getPrimaryWalletAccount();

if (walletAccount && isStarknetWalletAccount(walletAccount)) {
  const { account } = await getStarknetAccount({ walletAccount });

  // Use the account to interact with the Starknet blockchain
  // For example, invoke a contract method:
  const result = await account.execute({
    contractAddress: "0x...",
    entrypoint: "transfer",
    calldata: ["0x...", "100"],
  });

  console.log("Transaction hash:", result.transaction_hash);
}

Parameters

ParameterTypeDescription
walletAccountStarknetWalletAccountThe wallet account to get the Starknet account for
clientDynamicClient (optional)The Dynamic client instance. Only required when using multiple clients.

Returns

Promise<{ account: WalletAccount }> - A promise that resolves to an object containing a WalletAccount instance from starknet.

Errors

ErrorDescription
NotStarknetProviderErrorThrown if the wallet account’s provider is not a Starknet provider