This tutorial will show you how to create a web3 peer-to-peer payment application like Venmo using Streambird’s APIs, you will need to follow a few steps. Streambird provides a Wallet as Service API that allows you to create platform-controlled wallets. With Streambird’s APIs, you can easily build a payment application that enables users to send and receive payments in different cryptocurrencies, just like Venmo does with fiat currencies.

To create this payment application, you’ll need to follow several steps. First, you’ll need to create users and wallets using Streambird’s APIs. Then, you’ll need to integrate these APIs into your application to allow users to create, fund, and manage their wallets. Finally, you’ll need to implement the transfer functionality to enable users to send and receive payments.

In this tutorial, we’ll guide you through each step of the process, providing detailed explanations and examples for each API endpoint. By the end of this tutorial, you’ll have a working payment application that utilizes Streambird’s APIs, allowing users to seamlessly send and receive cryptocurrency payments.

Step 1: Create a user account

To use Streambird’s APIs, you need to create a user account first. You can use the following curl command to create a user:

cURL
curl \
 -X POST https://api.streambird.io/v1/auth/users/create \
 -H "Authorization: Bearer $API_KEY" \
 -H "Content-Type: application/json" \
 -d '{"first_name":"John","last_name":"Smith","email":"sandbox@streambird.io","phone_number":"+14152222222","requires_verification":true}'

In the above command, replace $API_KEY with your Streambird secret API key for backend. This will create a user with the provided details.

Step 2: Create a wallet for user

Now that you have created a user account, the next step is to create a wallet for the user. You can use the following curl command to create a wallet:

cURL
curl \
 -X POST https://api.streambird.io/v1/wallets/create \
 -H "Authorization: Bearer $API_KEY" \
 -H "Content-Type: application/json" \
 -d '{"wallet_type":"ETH","user_id":"user_2Cu2uVhYy0OVgRcO913OsqIVaPI"}'

In the above command, replace $API_KEY with your Streambird access token and user_2Cu2uVhYy0OVgRcO913OsqIVaPI with the user ID you created in Step 1. This will create a new wallet for the user with the specified token symbol and name.

Step 3: Fund the wallet

To enable users to make transactions, their wallets need to have sufficient funds. For testing, you can go to an Ethereum faucet and request testnet Ethereum. The testnet Ethereum is not real Ethereum, but it behaves in the same way and is ideal for testing purposes.

If you’re developing a live application, you’ll need to integrate an on-ramp such as MoonPay to enable users to purchase cryptocurrency with fiat currencies and fund their wallets. MoonPay allows users to buy a variety of cryptocurrencies using fiat currency and supports multiple payment methods including credit cards, Apple Pay, and bank transfers.

Once your users have funded their wallets, they’ll be able to make transactions using the cryptocurrency in their wallets. In the next section, we’ll walk you through how to implement the transfer functionality so that users can send and receive payments using Streambird’s APIs.

Step 4: Make transfers between wallets

To create a transfer, you need to use the POST /v1/transfers/create API endpoint. This endpoint allows you to specify the source wallet, the destination wallet, the amount to transfer, and other details such as notes and whether the transfer amount includes fees.

Here’s an example cURL request to create a transfer:

cURL
curl \
 -X POST https://api.streambird.io/v1/transfers/create \
 -H "Authorization: Bearer $API_KEY" \
 -H "Content-Type: application/json" \
 -d '{"dest_currency":"ETH","source":"wallet_2DJJmE5IhB1M7I8jJ7JuyCiOtiC","dest":"0xF7E9D631bfBd90C19691566Db4AB96697A2663C6","source_amount":"0.005","notes":"test","amount_includes_fees":true,"user_id":"user_2Cu2uVhYy0OVgRcO913OsqIVaPI"}'

When you make this API call, Streambird will return an unconfirmed Transfer object that contains the source_amount, dest_amount, and total_fees. The dest_amount is the total amount that the recipient will receive after fees have been deducted.

Step 5: Confirm the transfer

To confirm the transfer and actually process the payment, you need to use the POST /v1/transfers/{transfer_id}/confirm API endpoint. You’ll need to replace {transfer_id} with the ID of the transfer that you created in the previous step.

Here’s an example cURL request to confirm a transfer:

cURL
curl \
-X POST [https://api.streambird.io/v1/transfers/{transfer_id}/confirm](https://api.streambird.io/v1/transfers/%7Btransfer_id%7D/confirm) \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"user_id":"user_2Cu2uVhYy0OVgRcO913OsqIVaPI"}'

When you make this API call, Streambird will process the transfer and update the status of the Transfer object to pending from unconfirmed. The funds will be transferred from the source wallet to the destination wallet.

Note that the user_id parameter is optional, but can be used to trigger a platform validation to ensure that the source wallet is owned by the specified user, which can help prevent usage errors. Once the transfer is confirmed, the specified amount will be moved from the source wallet to the destination wallet.

It’s important to note that before testing, the wallets must be funded with the appropriate amount of tokens. For testing purposes, you can go to an Ethereum faucet to get free testnet ETH, or if it’s a live app, you can use an on-ramp such as MoonPay to fund the wallets.

Conclusion

Congratulations! You have successfully built a peer-to-peer payment application like Venmo using Streambird’s APIs. By following these steps, you have learned how to create a new user, create a wallet, fund the wallets, and create and confirm transfers.

Now that you have built the basic functionality, you can continue to add more features and improve the user experience. For example, you could add a feature that allows users to view their transaction history, send reminders for pending payments, or add support for additional cryptocurrencies. Streambird supports a wide range of cryptocurrencies including Bitcoin, Ethereum, Solana, and more.

Remember, when building a web3 application, it is important to ensure the security of your users’ funds and personal information, you can leverage Streambird’s Authentication APIs to help you with this.

We hope this tutorial has been helpful in getting you started on your journey to building a Web3 payment application. Good luck!