This project demonstrates the integration of Turnkey for wallet management and Gelato Relay for gasless transactions using sponsoredCallERC2771
. The frontend is built with Next.js and utilizes Viem for blockchain interactions.
-
Turnkey Integration:
- Create and manage wallets using Turnkey's Passkey API.
- Secure login and sub-organization management.
- Viem-powered blockchain interactions.
-
Gelato Relay Integration:
- Gasless transactions via
sponsoredCallERC2771
. - Increment a counter on contracts deployed on Base Sepolia and Arbitrum Sepolia.
- Gasless transactions via
- Node.js: Install Node.js (v16 or later).
- Turnkey API Key: Obtain from Turnkey.
- Gelato API Key: Register and get a key from Gelato Network.
Fill out the .env
file with the required keys.
-
Clone the repository:
git clone https://github.com/gelatodigital/gelato-tunrkey-passkeys-relay.git cd gelato-tunrkey-passkeys-relay
-
Install dependencies:
pnpm install
-
Start the development server:
pnpm run dev
-
Create a wallet:
- Click Create New Wallet on the homepage.
- A wallet will be created under a Turnkey Sub-Organization.
-
Login:
- Click Login to sub-org with existing passkey to log in with an existing wallet.
const fetchCounterValue = async (network: "baseSepolia" | "arbSepolia") => {
const publicClient = createPublicClient({
chain: network === "baseSepolia" ? baseSepolia : arbitrumSepolia,
transport: http(),
});
const counterValue = await publicClient.readContract({
address:
network === "baseSepolia"
? COUNTER_CONTRACT_ADDRESS
: ARBITRUM_SEPOLIA_CONTRACT_ADDRESS,
abi,
functionName: "contextCounter",
args: [wallet.address],
});
setCounterValue(Number(counterValue));
};
const sponsoredCallIncrementCounter = async (
network: "baseSepolia" | "arbSepolia"
) => {
const relay = new GelatoRelay();
const incrementData = encodeFunctionData({
abi,
functionName: "increment",
args: [],
});
const relayRequest = {
user: wallet.address,
chainId: BigInt(await viemClient.getChainId()),
target:
network === "baseSepolia"
? COUNTER_CONTRACT_ADDRESS
: ARBITRUM_SEPOLIA_CONTRACT_ADDRESS,
data: incrementData,
};
const relayResponse = await relay.sponsoredCallERC2771(
relayRequest,
viemClient,
GELATO_API_KEY
);
console.log(`Transaction submitted! Task ID: ${relayResponse.taskId}`);
};
- Base Sepolia
- Arbitrum Sepolia
-
Build the project:
pnpm run build
-
Deploy the project:
pnpm run start
Feel free to open issues or create pull requests for suggestions and improvements!