πŸ‘ Wallet Implementation

Developers can use this documentation to generate a wallet public key.

Overview

Coinflow identifies every end-user making a purchase with a wallet. You can think of the wallet as a unique customer ID that helps us identify the customer. Merchants whose end-users don’t have crypto wallets can use the below code snippets to generate a wallet and pass it to Coinflow.

Generate Wallet Public Keys

Some Coinflow endpoints will require you to pass a wallet public key in the x-coinflow-auth-wallet header. The CoinflowPurchase component will also require you to pass a wallet object. The below snippets are examples of how you can generate a wallet public key from a unique customer id. The unique customer id should be identified by you, the merchant. Examples of what you can use here are: a UUID you use internally to identify the end-user or the end-user’s email address.

Public Keys on EVM Chains

How to generate pubkeyfor EVM chains:

Javascript
1const crypto = require('crypto');
2
3async function createPubKey() {
4 const userId = '123456789abcdefg'; // Replace this with any string that uniquely identifies the user in your system.
5 const hash = crypto
6 .createHash('sha256')
7 .update(userId)
8 .digest('hex')
9 .substring(0, 40);
10 const pubkey = `0x${hash}`;
11 console.log(pubkey); // The public key to pass onto coinflow
12}
13
14createPubKey();

Public Keys on Solana

How to generate pubkeyfor Solana:

1import * as web3 from '@solana/web3.js';
2import * as crypto from 'crypto';
3
4async function createPubKey() {
5 const userId = '123456789abcdefg'; // Replace this with any string that uniquely identifies the user in your system.
6 const hash = crypto
7 .createHash('sha256')
8 .update(userId)
9 .digest();
10
11 // Creates a Keypair from the hashed value
12 const keyPair = web3.Keypair.fromSeed(hash.slice(0, 32)); // Seed must be 32 bytes
13
14 const pubkey = keyPair.publicKey.toBase58();
15 console.log(pubkey); // The public key to pass onto coinflow
16}
17
18createPubKey();

Generate Solana Wallet Objects

Generate A Solana Wallet From Email Address

Merchants implementing CoinflowPurchase can use the following code snippet to generate a Solana wallet object from an end-user’s email address and pass it into the wallet prop. This feature is supported in React, Vue, and Angular for Coinflow package version 10.2.10 or later.

1// How to create a wallet for the payer
2// Creating a wallet for the payer is necessary to enable saved payments.
3const getWallet = async (
4 email: string,
5 env: 'sandbox' | 'prod'
6): Promise<SolanaWallet | null> => {
7 return CoinflowUtils.getWalletFromEmail({ email, merchantId: '<YOUR_MERCHANT_ID>', env });
8};
9
10const [wallet, setWallet] = useState<SolanaWallet| null>(null);
11useEffect(() => {getWallet(email).then(setWallet)}, [email]);
12
13if (!wallet) return null;
14
15// Passing the wallet to the CoinflowPurchase component
16<CoinflowPurchase
17 ...
18 wallet={wallet} // pass the wallet generated from getWallet()
19/>

Generate a Solana Wallet Object From User Id

Merchants integrating CoinflowPurchase can utilize the code snippet below to generate a Solana wallet object using a user ID of your choice. This userId can be any string you use to identify your customer, and the returned wallet object should be passed into the wallet prop. This functionality is available in React, Vue, and Angular with Coinflow package version 10.2.10 or later.

1// How to create a wallet for the payer
2async function createWallet() {
3 return await CoinflowUtils.getWalletFromUserId({
4 userId: '<USER_ID>',
5 merchantId: '<YOUR_MERCHANT_ID>',
6 env: 'sandbox' | 'prod'
7 });
8}
9
10const [wallet, setWallet] = useState<SolanaWallet | null>(null);
11
12useEffect(() => {
13 createWallet().then(setWallet).catch((error) => {
14 console.error('Failed to create wallet:', error);
15 });
16}, []);
17
18if (!wallet) return null;
19
20// Passing the wallet to the CoinflowPurchase component
21<CoinflowPurchase
22 // other props
23 wallet={wallet} // pass the wallet generated from createWallet()
24/>