blog_Next.js-1

Discover how a Next.js server interfaces with Circle’s Programmable Wallets API to initialize wallets, then prompts the iOS SDK for PIN & security question setup

Next.js, the popular React framework, can seamlessly integrate with external services and APIs. In this tutorial, we will walk through a server-side function in Next.js that simplifies the process of initializing Circle’s Programmable Wallets. Initialization is crucial to a wallet because it ensures that each individual is given a distinct identity within the system, allowing for personalized interactions and wallet security. This is particularly helpful for developers who want a streamlined workflow without the hassle of handling multiple API calls. To demonstrate this integration, our demo application will showcase how Next.js server-side scripts can be paired with an iOS app, enabling users to effortlessly setup a pin code for their first wallet.

Building Wallet Initialization Server:

Our server-side function consolidates three POST requests into one, making it easy for developers to initialize and create a user wallet. Additionally, it aids in setting up the PIN code and security questions for the wallet using the iOS SDK on a mobile device.

Setting It Up (Full code available in our Github Repo):

Let’s dive into the code to understand how it functions:

1. Generating a User ID:

//app/api/user/route.js
const user_id = v4();

 

Here, we are utilizing the

`uuid`
library to generate a unique user ID for the new user. This ID will be used in subsequent API requests.

 

2. Creating a User:

//app/api/user/route.js
const res1 = await fetch(process.env.CIRCLE_BASE_URL + 'users', { method: 'POST', headers: { 'Authorization': `Bearer ${process.env.CIRCLE_API_KEY}`, 'Content-Type:' 'application/json', }, body: JSON.stringify({ 'userId': user_id, }) }); const data1 = await res1.json();

 

 

Disclaimer

*Programmable Wallets application programming interface (“API”) is offered by Circle Technology Services, LLC (“CTS”). CTS is not a regulated financial services company and the API does not include financial, investment, tax, legal, regulatory, accounting, business, or other advice. For additional details, please click here to see the Circle Developer terms of service.

Back to top