img
AboutContactBlogGet in touch

8 min read

Laravel Crypto Wallet Package: Simplify Cryptocurrency Integration in Laravel

Interested in generating passive income? Join our partnership program and receive a commission on each new client referral. Learn more.

Laravel crypto wallet packageOne of our talented developers, Kote Khomeriki, has recently developed a Laravel Crypto Wallet package that simplifies integrating and managing crypto wallets. In this blog, Kote shares the story behind the package, what inspired him to build it, and how you can set it up yourself. So, let’s jump right in.

Laravel Crypto Wallet Package

The Laravel Crypto Wallet is an open-source package that simplifies how Laravel communicates with blockchain service providers. It acts as a unified wrapper for various providers’ APIs and simplifies complex interactions with cryptocurrency wallets. With this package, you can easily generate wallets and addresses, transfer funds, view your wallet balances, track transaction history, and more - all directly from your Laravel application. By bringing multiple crypto service providers under one roof, it makes blockchain integrations, managing transactions, and handling other wallet-related operations more straightforward.

The Idea Behind the Package

The idea for the Laravel Crypto Wallet package came from a project I was working on where I needed to integrate a crypto payment provider. We chose BitGo at the time because it offered a broad range of features, supported multiple coins, and had solid documentation. However, since there was no existing package for BitGo that met my needs and requirements, I thought to myself:👇 

laravel crypto wallet package
While developing the package, I drew inspiration from Laravel Cashier. Cashier works with two adapters - Cashier and Paddle - and provides a clean and straightforward way for handling subscriptions and payments. This approach lets you interact with services like Stripe without worrying about raw API calls. I wanted to bring this same simplicity and flexibility to the Crypto Wallet package, covering multiple service providers and breaking everything down into granular, reusable components.

Although Cashier and the crypto wallet package serve different purposes, the flexibility and ease of use that Cashier offers definitely guided the development of this package.

How Does It Work?

Getting started with the Laravel Crypto Wallet package is straightforward. You should just follow these steps to set up your environment and integrate BitGo smoothly.

1. Package Installation

First, install the package using Composer. Run the following command in your project directory:

composer require redberryproducts/laravel-crypto-wallet  

2. Set Up Your BitGo Account

To integrate BitGo, you’ll need to configure your account. Here’s how:

  1. Log in to BitGo using the following link.

  2. Once logged in, click on your user avatar and navigate to Enterprise Settings.

  3. Go to the General tab and copy your Enterprise ID - you’ll need this later when creating a wallet.

  4. Next, move to the Developer Options section and click the Create Access Token button.

  5. Fill out the form with the required information. After completing it, copy the generated token and save it in a secure location. This token will be used in your .env file.

3. Run BitGo Express Locally

To interact with BitGo’s Express API, you’ll need to run BitGo Express locally. Here’s how to do it using Docker:

  1. Pull the latest BitGo Express image:

    docker pull bitgo/express:latest  
  2. Run the container:

    docker run -it -p 3080:3080 bitgo/express:latest

This will start BitGo Express on port 3080. For more details, refer to the official BitGo Express Docker documentation.

4. Configure Your Environment

Now, it’s time to set up your environment variables. Add the following to your .env file:

BITGO_TESTNET = true

BITGO_API_KEY = YOUR-BITGO-API-KEY

BITGO_EXPRESS_API_URL = http://localhost:3080/api/v2/

BITGO_DEFAULT_COIN = tbtc4

BITGO_WEBHOOK_CALLBACK = https://yourapp.com/webhook/bitgo

Here’s what these variables mean:

  • BITGO_TESTNET: Set to true to use testnet blockchain.

  • BITGO_API_KEY: Your BitGo access token.

  • BITGO_EXPRESS_API_URL: The URL for your local BitGo Express instance.

  • BITGO_DEFAULT_COIN: The coin type you’ll use (e.g., tbtc4 for test Bitcoin).

  • BITGO_WEBHOOK_CALLBACK: The URL where BitGo will send webhook events (e.g., transaction updates).

After everything is set up and ready, you’re now ready to dive into the actual implementation.

Let’s review some examples of how the package is used in a showcase project:


Here, we see an invokable controller where a SendToManyRequest DTO is built with the data needed for the transfer. Then, the WalletManager is called with a BitGo instance for the authenticated user’s coin and wallet, and its sendTransferToMany method is invoked with the DTO. If a BitgoGatewayException or ConnectionException occurs, an error message is returned to the client; otherwise, the transfer result is returned as JSON.

Here, we see a queued listener for a UserRegisteredEvent and obtains the newly registered user’s information. Then, the WalletManager is called with a BitGo instance for the user’s coin, and its generate method is called with the wallet label, passphrase, and enterprise ID; after that, addWebhook is chained to the wallet to enable a webhook. If a BitgoGatewayException or ConnectionException occurs, a WalletGenerationFailedForRegisteredUser event is broadcasted; otherwise, the wallet details (coin, wallet ID, name, and passphrase) are saved to the user’s wallet record, and a WalletGeneratedEvent is broadcasted.

Possible Use Cases 

The Laravel Crypto Wallet package opens the door to a wide range of practical applications, making it versatile for various industries. Here’s how it can be used:

  • Personal Crypto Wallet Platforms

Create secure, multi-currency wallets that allow users to manage their cryptocurrencies effortlessly. With this package, you can enable features like wallet and address generation, balance tracking, and fund transfers - all tailored to individual needs.

Check out our showcase app built using this package to see it in action!

  • E-commerce Platforms Enabling Crypto Payments

Allow online stores to accept various cryptocurrencies as payment methods, offering customers alternative payment options and expanding market reach.

  • Hotels Accepting Cryptocurrency for Bookings

Enable hotels to accept crypto payments for room bookings and services, accommodating international and tech-savvy travelers.

  • Platforms Facilitating Crypto Donations

Support non-profits, crowdfunding sites, or creators in accepting cryptocurrency donations, providing transparency and diverse funding options.

  • SaaS Platforms with Crypto Payments and Subscriptions

Help SaaS businesses accept cryptocurrency for subscriptions or pay-as-you-go services. This flexibility in billing appeals to global users and simplifies transactions across borders.

  • Platforms Providing Crypto Payment Gateways

Develop solutions that enable businesses to integrate cryptocurrency payment gateways into their websites or applications. This facilitates seamless crypto transactions for their users.

  • Freelance and Gig Platforms Accepting Crypto Payments

Simplify payments for global talent on freelance platforms by offering cryptocurrency as a payment method. This allows faster, borderless transactions, benefiting both freelancers and clients.

  • Gaming Platforms Integrating Crypto Rewards

Incorporate cryptocurrency rewards and in-game purchases within gaming platforms, enhancing user engagement and providing alternative monetization methods.

  • Educational Platforms Accepting Crypto Tuition Fees

Allow educational institutions and online learning platforms to accept cryptocurrency payments for tuition, courses, and materials, attracting a diverse student base.

  • Event Ticketing Systems with Crypto Payments

Simplify ticket sales and merchandise purchases for event organizers by integrating cryptocurrency payments. This is especially beneficial for international attendees and helps reduce transaction fees.

Future Development Plans

Looking ahead, my goal is to add support for more service providers into the Laravel crypto package. After that, I plan to introduce a universal interface, so whether you’re using BitGo, Coinbase, or any other provider, you’ll get consistent responses and functionalities. All you’ll need to do is change the driver in the configuration, and everything will work the same. In short, I aim to make this package as universally usable as possible.

img

Meet the authors

We are a 200+ people agency and provide product design, software development, and creative growth marketing services to companies ranging from fresh startups to established enterprises. Our work has earned us 100+ international awards, partnerships with Laravel, Vue, Meta, and Google, and the title of Georgia’s agency of the year in 2019 and 2021.

img
Contact us