Wraps Stytch's Crypto Wallet Authenticate endpoint. Call this method to complete the authentication of a crypto wallet by passing the signature.
See Ethereum's EIP-1193 for an example of Ethereum's provider API.
Consumer Authentication
/
Frontend SDKs
/
Headless
/
Crypto Wallets
/
Authenticate
Wraps Stytch's Crypto Wallet Authenticate endpoint. Call this method to complete the authentication of a crypto wallet by passing the signature.
See Ethereum's EIP-1193 for an example of Ethereum's provider API.
import React, { useCallback } from 'react';
import { useStytch } from '@stytch/react';
export const Login = () => {
const stytch = useStytch();
const trigger = useCallback(async () => {
/* Request user's address */
const [crypto_wallet_address] = await ethereum.request({
method: 'eth_requestAccounts',
});
/* Ask Stytch to generate a challenge for the user */
const { challenge } = await stytch.cryptoWallets.authenticateStart({
crypto_wallet_address,
crypto_wallet_type: 'ethereum',
});
/* Ask the user to sign the challenge, this takes place on your frontend and uses the browser's built-in crypto provider API. */
const signature = await ethereum.request({
method: 'personal_sign',
params: [challenge, crypto_wallet_address],
});
/* Send the signature back to Stytch for validation */
await stytch.cryptoWallets.authenticate({
crypto_wallet_address,
crypto_wallet_type: 'ethereum',
signature,
session_duration_minutes: 60,
});
}, [stytch]);
return <button onClick={trigger}>Sign in with Ethereum</button>;
};
{
"challenge": "Signing in with Project: 7_EPetPqfdEiDCJtgad6-xsXytN3Ee9tx6mdRTQK3fC7-J2PDxpP1GAvYB9Ic4E09h-K88STiRIzKSGP",
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141"
"status_code": 200
}