Skip to main content

Signing Transactions

1. Initialize the Passkey Client

import { Turnkey } from "@turnkey/sdk-browser";
import turnkeyConfig from "./turnkey.json"

const turnkey = new Turnkey(turnkeyConfig);
const passkeyClient = turnkey.passkeyClient();

2. Initialize an Ethers Provider and Turnkey Signer

import { ethers } from "ethers";
import { TurnkeySigner } from "@turnkey/ethers";

const provider = new ethers.JsonRpcProvider(<provider api url>);
const currentUser = await turnkey.getCurrentUser();
const turnkeySigner = new TurnkeySigner({
client: passkeyClient,
organizationId: currentUser.organization.organizationId,
signWith: "<wallet address to sign with>"
})
const connectedSigner = turnkeySigner.connect(provider);

3. Call sendTransaction with the Turnkey Signer

const transactionRequest = {
to: "<destination address>",
value: ethers.parseEther("<amount to send>"),
type: 2
}
const sendTransaction = await connectedSigner.sendTransaction(transactionRequest);