@sky-mavis/ronin-crosschain-payment
v0.1.0-beta.6
Published
A simple SDK for cross-chain payments on Ronin
Keywords
Readme
Ronin Cross-chain Payment
A TypeScript SDK for handling cross-chain payments on Ronin network. This package provides a simple way to manage tokens and payments across different blockchain networks.
Features
- Built-in wallet proxy integration
- Cross-chain payment
Installation
# Using npm
npm install @sky-mavis/ronin-crosschain-payment
# Using yarn
yarn add @sky-mavis/ronin-crosschain-payment
## Usage
### Basic Setup
```typescript
import { PaymentService } from '@sky-mavis/ronin-crosschain-payment';
import { mainnet } from 'viem/chains';
const paymentService = new PaymentService({
chains: [mainnet], // Add the chains you want to support
});Get Quote for Token Exchange
import { QuoteParams } from '@sky-mavis/ronin-crosschain-payment';
const quoteParams: QuoteParams = {
from: {
chainId: 1,
tokenAddress: '0x...',
userAddress: '0x...',
rawAmount: '1000000000000000000'
},
to: {
chainId: 2020,
tokenAddress: '0x...',
},
config: {
slippageBps: 100,
tradeType: 'exact_in'
}
};
const quote = await paymentService.getQuote(quoteParams);Execute Transaction
import { createWalletClient, custom } from 'viem';
// Create a wallet client using viem
const walletClient = createWalletClient({
chain: mainnet,
transport: custom(window.ethereum)
});
// Execute the transaction using the quote
await paymentService.executeTransaction(
quote.data.bestQuote,
walletClient,
(progress) => {
console.log('Transaction progress:', progress);
}
);Get Token Balances
const balances = await paymentService.getTokens({
chainId: 1,
userAddress: '0x...',
tokenAddresses: ['0x...', '0x...']
});API Reference
PaymentService
Constructor
constructor(configs: PaymentServiceConfigs)configs.chains: Array of supported blockchain chains (viem Chain objects)
Methods
getQuote
async getQuote(params: QuoteParams): Promise<QuoteResponse>Generates a quote for token exchange across chains.
executeTransaction
async executeTransaction(
quote: Quote,
walletClient: WalletClient,
onProgress?: (data: ProgressData) => void
)Executes a cross-chain transaction based on the provided quote.
getTokens
async getTokens(params: GetTokenBalanceParams): Promise<TokenBalance[]>Retrieves token balances for a given user address.
Development
# Install dependencies
yarn install
# Build the package
yarn build
# Run tests
yarn test