Discover how to integrate Bolt.new AI with Plaid to streamline financial data management and payments. Follow our expert guide for a seamless setup.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
package.json
file if it doesn’t exist. Since Bolt.new AI lacks a terminal, add your dependencies directly in this file. Ensure you have the Plaid client library listed. Insert the following snippet into your package.json
:
{
"name": "your-project-name",
"version": "1.0.0",
"dependencies": {
"plaid": "^12.0.0",
"express": "^4.18.0"
}
}
PLAIDCLIENTID=yourplaidclient_id
PLAIDSECRET=yourplaid_secret
PLAID_ENV=sandbox
Replace yourplaidclientid
and yourplaid_secret
with your actual Plaid credentials.
plaidIntegration.ts
. This module will handle all interactions with Plaid.
plaidIntegration.ts
:
import { Configuration, PlaidApi, PlaidEnvironments } from 'plaid';
const configuration = new Configuration({
// Use the environment variable to set the Plaid environment (sandbox, development, production)
basePath: PlaidEnvironments[process.env.PLAID_ENV as keyof typeof PlaidEnvironments],
baseOptions: {
headers: {
'PLAID-CLIENT-ID': process.env.PLAIDCLIENTID || '',
'PLAID-SECRET': process.env.PLAID_SECRET || '',
},
},
});
export const plaidClient = new PlaidApi(configuration);
/**
- Creates a Link token for a user.
- @param userId A unique identifier for the user.
*/
export async function createLinkToken(userId: string): Promise {
const request = {
user: {
clientuserid: userId,
},
client_name: 'Your App Name',
products: ['transactions'], // Update products as needed by your integration
country_codes: ['US'],
language: 'en',
};
const response = await plaidClient.linkTokenCreate(request);
return response.data.link_token;
}
app.ts
or index.ts
), you need to set up an API endpoint that uses the createLinkToken
function from your plaidIntegration.ts
module.
import express from 'express';
import { createLinkToken } from './plaidIntegration';
const app = express();
app.use(express.json());
// Endpoint to create a Plaid Link token
app.post('/api/create-link-token', async (req, res) => {
const userId = req.body.userId;
if (!userId) {
return res.status(400).json({ error: 'User ID is required.' });
}
try {
const linkToken = await createLinkToken(userId);
res.json({ link_token: linkToken });
} catch (error: any) {
res.status(500).json({ error: error.message });
}
});
// Set the port from environment or default to 3000
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(Server running on port ${PORT});
});
/api/create-link-token
endpoint to obtain a Plaid Link token.
async function fetchLinkToken(userId: string) {
try {
const response = await fetch('/api/create-link-token', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ userId })
});
const data = await response.json();
if (response.ok) {
// Use the link token to initialize the Plaid Link flow in your UI
console.log('Link Token:', data.link_token);
} else {
console.error('Error fetching link token:', data.error);
}
} catch (err) {
console.error('Error:', err);
}
}
Ensure that you call this function at the appropriate time in your UI workflow (such as when a user clicks a button to connect their bank account).
package.json
, plaidIntegration.ts
, your server file (app.ts
or index.ts
), and any client-side files.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.