Skip to main content

JavaScript/TypeScript SDK

Effortless Web3 wallet UX for browser-based games with our simple-to-use JavaScript SDKs.

Overview

The JavaScript/TypeScript SDK is designed for web-based games, offering developers the ability to integrate Babylon Wallet seamlessly into their web-based projects. The SDK provides a comprehensive set of features for wallet creation, message signing, asset transactions, and user authentication, all in a secure way without players having to leave the game.

Packages

This is a multi-repo consisting of the following packages:

PackageDescription
@bltzr-gg/babylon-wallet-sdk-ts-browser-walletBrower wallet
@bltzr-gg/babylon-wallet-sdk-ts-ethereum-providerEthereum provider for ethers.js
@bltzr-gg/babylon-wallet-sdk-ts-transport-core(Internal) Core package for communicating with the wallet
@bltzr-gg/babylon-wallet-sdk-ts-transport-iframe(Internal) Package for communicating with the wallet via iframe

Installation

npm

npm install --save @babylon/wallet-sdk-ts

yarn

yarn install @babylon/wallet-sdk-ts

Usage

To use the Babylon Wallet SDK with ethers.js, follow this example:

// Import the stylesheet
import '@bltzr-gg/babylon-wallet-sdk-ts-browser-wallet/lib/styles/wallet-modal.css'

const provider = new providers.JsonRpcProvider(
'https://your-rpc.example'
)

const wallet = new BrowserWallet<BabylonWalletSigner>(
BabylonWalletSigner,
[provider],
{
name: 'My Game',
logo: window.location.origin + `/game-logo.jpg`
}
)

// Get wallet address
const address = await wallet.provider.getAddress()

// Sign a message
const signedMessage = await wallet.provider.signMessage('hello')

// Disallow burner wallets. Subsequent wallet operations
// will require an authenticated wallet (perma-wallet).
wallet.provider.setAllowBurner(false)

// Sign and send transaction
const feeData = await provider.getFeeData()
const response = await wallet.provider.sendTransaction({
type: 2,
from: address,
to: 'vitalik.eth',
value: parseEther('0.05'),
maxFeePerGas: feeData!.maxFeePerGas,
maxPriorityFeePerGas: feeData!.maxPriorityFeePerGas,
chainId: 80001
})

Dependencies

Support

If you need assistance or have any questions, please reach out to us at badass@bltzr.gg