Skip to main content

Use Starknet

Starknet is a non-EVM Layer 2 network. You can interact with users' Starknet accounts in MetaMask by connecting to the Starknet Snap.

You can use the get-starknet library or the wallet_invokeSnap JSON-RPC method from your dapp to connect to the Starknet Snap. Both options support similar functionalities, but offer different ways of interacting with users' Starknet accounts. See Connect to Starknet to get started.

The following sections compare the two connection options.

get-starknet

Important

We recommend using the get-starknet library for most use cases due to its ease of configuration and multi-wallet support. Learn more about how get-starknet interacts with MetaMask.

The get-starknet library:

  • Provides a high-level API that abstracts complex operations.
  • Standardizes error handling.
  • Supports connecting to multiple Starknet wallets, not limited to MetaMask.
  • Manages wallet connections and Starknet interactions.
  • Provides results in more readable code.

get-starknet provides the same functionalities as wallet_invokeSnap and integrates a Starknet Window Object (SWO). The SWO simplifies account management and signing, and enhances the experience of handling account states and transactions. A dapp uses the Account object in the SWO to manage operations.

wallet_invokeSnap

The wallet_invokeSnap method:

  • Requires precise method names and parameter structures.
  • Handles both MetaMask-specific and Starknet-specific errors.
  • Is designed for operating within the MetaMask framework.
  • Manages lower-level Starknet interactions directly.
  • Provides results in more detailed, lower-level code.

wallet_invokeSnap manages direct interactions between the dapp and the Starknet Snap. It facilitates network communication for account creation, transaction signing, fee estimation, and other Starknet-related actions.

Supported functionalities

The following section lists the core functionalities and API methods that each connection option supports:

Account management
Functionalityget-starknetwallet_invokeSnap
Deploy an accountdeployAccount ↗starkNet_createAccount
Recover an account addressgetAddress ↗starkNet_recoverAccounts
Display a private keystarkNet_displayPrivateKey
Gas and fees
Estimate the gas feeestimateFeeBulk ↗starkNet_estimateFee
Estimate the account deploy feeestimateAccountDeployFee ↗starkNet_estimateAccountDeployFee
Token management
Add an ERC-20 tokenwatchAsset ↗starkNet_addErc20Token
Get the ERC-20 token balancecallContract ↗starkNet_getErc20TokenBalance
Signing and transactions
Sign a messagesignMessage ↗starkNet_signMessage
Sign a transactionsignTransaction ↗starkNet_signTransaction
Sign a declare transactionsignDeclareTransaction ↗starkNet_signDeclareTransaction
Verify a signed messagestarkNet_verifySignedMessage
Execute a transactionexecute ↗starkNet_executeTxn
Declare a contractdeclareContract ↗starkNet_declareContract
Network management
Switch networksswitchNetwork ↗starkNet_switchNetwork
Get the current networkgetChainId ↗starkNet_getCurrentNetwork
Get transactionsgetTransaction ↗starkNet_getTransaction
Get the transaction statusgetTransactionStatus ↗starkNet_getTransactionStatus