Skip to main content

Sign Starknet transactions

You can sign Starknet transactions using the get-starknet library or the wallet_invokeSnap JSON-RPC method.

Prerequisites

Connect to Starknet from your dapp.

Sign a transaction

Sign a Starknet transaction using the following:

const signStarknetTransaction = async (wallet, contractAddress, entrypoint, calldata) => {
try {
if(wallet?.isConnected !== true){
throw("Wallet not connected");
}

// Sign the transaction.
const result = await wallet?.account?.signer.signTransaction({
contractAddress: contractAddress, // The address of the contract.
entrypoint: entrypoint, // The function to call in the contract.
calldata: calldata // The parameters to pass to the function.
});
console.log("Transaction signed successfully:", result);
return result;
} catch (error) {
console.error("Error signing transaction:", error);
}
};