@blockbolt/monad-wallet
v1.0.0
Published
BlockBolt package for Monad wallet
Maintainers
Readme
BlockBolt Monad Wallet SDK
The BlockBolt SDK for the Monad Wallet offers a streamlined and efficient way to integrate Monad blockchain payments. It provides a developer-friendly interface for processing transactions securely on the Monad chain. The SDK simplifies payment processing by handling transaction creation, signing, and status tracking, ensuring reliable delivery of payments to merchant addresses. By leveraging Viem's modern TypeScript support, it offers type-safe interaction with the Monad blockchain, making integration straightforward while maintaining high security standards.
Features
- Simple payment SDK for Monad blockchain using BlockBolt
- Built with Viem for modern TypeScript support
- Full transaction receipt access
- Explorer URL generation
- Comprehensive error handling
Installation
npm install @blockbolt/monad-walletUsage
Basic Example
import { BlockBolt } from "@blockbolt/monad-wallet";
import { privateKeyToAccount } from "viem/accounts";
// Initialize the BlockBolt SDK
const monadSdk = new BlockBolt();
// Create payment details
const paymentDetails = {
orderId: "ORDER123",
amount: "0.01", // Amount in MON tokens
merchantName: "Coffee Shop",
merchantAddress: "0x55Eca4d519Ca2BdC60C8f886aB00B5281772E517",
};
const account = privateKeyToAccount("0xYourPrivateKeyHere");
// Make payment
async function sendPayment() {
try {
const result = await monadSdk.makePayment(account, paymentDetails);
console.log(`Transaction sent! Hash: ${result.hash}`);
// Get explorer URL
const url = monadSdk.getExplorerUrl(result.hash);
console.log(`View transaction: ${url}`);
// Check transaction status
const status = await monadSdk.getTransactionStatus(result.hash);
if (status.status === "success") {
console.log("Payment confirmed!");
}
} catch (error) {
console.error("Payment failed:", error.message);
}
}
sendPayment();API Reference
BlockBolt
Main class for interacting with the BlockBolt Monad payment contract.
Constructor
constructor();Initializes the SDK with the default contract address and Monad Testnet configuration.
Methods
makePayment
public async makePayment(
account: Account,
paymentDetails: PaymentDetails
): Promise<TransactionResult>Makes a payment using the specified account and payment details.
Parameters:
account: Viem account object with the signerpaymentDetails: Object containing payment informationorderId: Unique identifier for the orderamount: Amount of MON tokens to sendmerchantName: Name of the merchantmerchantAddress: Address of the merchant
Returns:
TransactionResult: Object containing the transaction hash
getTransactionStatus
public async getTransactionStatus(hash: Hash)Gets the status and details of a transaction.
Parameters:
hash: Transaction hash to check
Returns:
- Object containing:
status: Transaction status ('success' or 'reverted')blockNumber: Block number where the transaction was minedlogs: Transaction logsreceipt: Full transaction receipt
getExplorerUrl
public getExplorerUrl(hash: Hash): stringGenerates a block explorer URL for the transaction.
Parameters:
hash: Transaction hash
Returns:
- URL string for the transaction on Monad block explorer
Error Handling
The SDK provides custom error classes for better error handling:
BlockBoltSDKError: Base error class for all SDK errorsTransactionError: Error related to transaction execution
Example:
try {
await monadSdk.makePayment(account, paymentDetails);
} catch (error) {
if (error instanceof TransactionError) {
console.error("Transaction failed:", error.message);
} else {
console.error("Unknown error:", error);
}
}Development
Building
npm run buildTesting
npm testLicense
MIT
