Skip to main content

actions/createWeb3Challenge

Actions

CreateWeb3ChallengeFn()

CreateWeb3ChallengeFn: (params) => Promise\<ChallengeResponse>

Create a challenge for a wallet. The web-sdk will use this to sign a message and prove ownership of a wallet.

Parameters

params: GenerateWalletChallengeRequest

The parameters to create the challenge with

Returns

Promise\<ChallengeResponse>

A promise that resolves to the challenge content

Example

Basic usage:

import { createSdk } from "@compilot/js-sdk";

const compilotSdk = createSdk({ apiKey });

const challengeContent = await compilotSdk.createWeb3Challenge({
address: "0xabc",
namespace: "eip155",
blockchainId: "1",
origin: "https://example.com",
workflowId: "4f7b537f-0ae0-429c-98c8-3f6555ef23d6",
externalCustomerId: "123",
});

More often used as part of an api to protect the api key. Please find below an example of how to use the createWeb3Challenge function in Next.js:

import { createSdk } from "@compilot/js-sdk";

const compilotSdk = createSdk({ apiKey });

export default async function handler(req: NextApiRequest, res: NextApiResponse ) {
if (req.method !== "POST") {
res.setHeader("Allow", ["POST"]);
res.status(405).end(`Method ${req.method} Not Allowed`);
return;
}

const challengeContent = await compilotSdk.createWeb3Challenge({
address: "0xabc",
namespace: "eip155",
blockchainId: "1",
origin: "https://example.com",
workflowId: "4f7b537f-0ae0-429c-98c8-3f6555ef23d6",
externalCustomerId: "123",
});

// Return the challenge to the client
res.status(200).json(challengeRes);
}