Documentation Index
Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
Use this file to discover all available pages before exploring further.
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
| Parameter | Type | Description |
|---|
walletAccount | StarknetWalletAccount | The wallet account to get the Starknet account for |
client | DynamicClient (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
| Error | Description |
|---|
NotStarknetProviderError | Thrown if the wallet account’s provider is not a Starknet provider |
React
import { getStarknetAccount, isStarknetWalletAccount } from '@dynamic-labs-sdk/starknet';
import { useWalletAccounts } from '@dynamic-labs-sdk/react-hooks';
import { useState } from 'react';
function StarknetContractButton({ contractAddress }) {
const walletAccounts = useWalletAccounts();
const walletAccount = walletAccounts.find(isStarknetWalletAccount);
const [txHash, setTxHash] = useState('');
const handleExecute = async () => {
if (!walletAccount) return;
const { account } = await getStarknetAccount({ walletAccount });
const result = await account.execute({
contractAddress,
entrypoint: 'transfer',
calldata: ['0x...', '100'],
});
setTxHash(result.transaction_hash);
};
return (
<div>
<button onClick={handleExecute} disabled={!walletAccount}>Execute</button>
{txHash && <p>Tx hash: {txHash}</p>}
</div>
);
}