This code demonstrates how to use a custom user ID to deterministically generate a PKP. This enables us to know the PKP public key and Ethereum address before minting the PKP.
You can read more about claimable keys here, and how to claim keys using a Lit Action here.
- Using an imported Ethereum private key, connect the wallet to the Lit RPC endpoint
Chronicle Yellowstone
. This will be used to pay for Lit usage - Use the
LitNodeClient
to connect to the Lit network - Connect the
LitContracts
client to the Lit network (datil-test
in this case) - If not provided in the .env file: Mint a
capacityCreditsNFT
and define the request limit and expiration date - Create a
capacityDelegationAuthSig
. Any network costs will be undertaken by thedAppOwnerWallet
- Generate the session signatures via an
AuthSig
(Authentication Signature) - Create a
userId
by combining an arbitrary string, which could be a username, and the current timestamp. This is to ensure theuserId
is unique - Execute the Lit Action. The Lit Action will derive a
keyId
from theuserId
- Use the
LitContracts.pubkeyRouterContract.read.getDerivedPubkey
method to derive a PKP public key from thekeyId
- Use the
litContractClient.pkpNftContract.write.claimAndMint
method to claim the derived PKP public key, and mint a new PKP that has the same public key - Wait for the transaction to finish, and derive the PKP public key, token ID, and ETH address from the transaction receipt
In this directory, lit-action-claim-key/nodejs
, run yarn
to install the project dependencies.
Make a copy of the provided .env.example
file and name it .env
:
cp .env.example .env
Within the .env
there are the ENVs:
ETHEREUM_PRIVATE_KEY
- Required- Must have Lit
tstLPX
tokens on theChronicle Yellowstone
blockchain - Will be used to mint the PKP and pay for Lit usage
- Must have Lit
LIT_CAPACITY_CREDIT_TOKEN_ID
- Optional- If not provided, a new
capacityCreditsNFT
will be minted and used. This enables theETHEREUM_PRIVATE_KEY
to pay for Lit usage
- If not provided, a new
After the .env
is configured, the test
NPM script in the package.json
will run a test that executes the example script. Run it using:
yarn test