Auth address signature generation
This guide walks you through generating a Signed Key Request using viem that need to be passed in while registering auth address
System & Installation Requirements
Prerequisites
- Node.js >= 18.x (LTS recommended)
- npm >= 9.x OR yarn >= 1.22.x
Download and install node (if not installed)
Initialize project (optional)
Install viem
OR with yarn:
Code Breakdown and Steps
You can find full code at the end of this guide.
Import the required functions
The code starts by importing the necessary libraries:
Generate a random mnemonic and derive the auth address
Generates a mnemonic and converts it to an Ethereum address (auth_address
)
Define EIP-712 domain
Describes the EIP-712 domain (context of signature).
Define the EIP-712 message structure
Defines the structure of the message to be signed.
Encode the auth_address
Encodes auth_address
as 32 bytes.
App details
Replace "MNEMONIC_HERE"
with your app mnemonic phrase and fid with your app’s fid.
Define a deadline
Sets a 24-hour expiration time.
Sign the EIP-712 message
Signs the message per EIP-712 standard.
Create a sponsor signature
If you want to sponsor the auth address, you can sign the EIP-712 signature again with a basic Ethereum signature. This route needs to be sponsored if not provided then neynar will sponsor it for you and you will be charged in compute units.
Print output
Prints useful values for further use.
Run the code
Save the code in a file, e.g., generateSignedKeyRequest.js
, and run it using Node.js:
cURL
Use the generated values to make a cURL request to register the auth address.
Replace <api-key>
with your actual API key and <string>
with your redirect URL(if needed).
Full Final Code
Enjoy building! 🚀
For additional help, feel free to contact us.