@ar-packages-changeit/sdk-ergo
v0.0.1
Published
Ergo chain specific functions of Rosen SDK to interact with and create transactions on Rosen Bridge
Readme
@ar-packages-changeit/sdk-ergo
Table of contents
Introduction
This package provides Ergo chain-specific functionality for the Rosen Bridge SDK, enabling you to interact with and create transactions on the Rosen Bridge for the Ergo blockchain.
Installation
npm:
npm i @ar-packages-changeit/sdk-ergoyarn:
yarn add @ar-packages-changeit/sdk-ergoUsage
Initialize the SDK
To use the SDK, initialize an instance of ErgoRosenChainSDK with your token configuration and lock address:
import { NETWORKS } from '@ar-packages-changeit/sdk-constant';
import { ErgoRosenChainSDK } from '@ar-packages-changeit/sdk-ergo';
import { DummyLogger } from '@rosen-bridge/abstract-logger';
import { TokenMap } from '@rosen-bridge/tokens';
const rosenTokens = [
{
ergo: {
tokenId: 'erg',
name: 'ERG',
decimals: 9,
type: 'native',
residency: 'native',
extra: {},
},
cardano: {
tokenId:
'04b95368393c821f180deee8229fbd941baaf9bd748ebcdbf7adbb14.7273455247',
name: 'rsERG',
decimals: 9,
type: 'CIP26',
residency: 'wrapped',
extra: {
policyId: '04b95368393c821f180deee8229fbd941baaf9bd748ebcdbf7adbb14',
assetName: '7273455247',
},
},
},
];
const tokenMap = new TokenMap();
await tokenMap.updateConfigByJson(rosenTokens);
const lockAddress = 'nB3L2P...'; // Rosen Ergo lock address
const sdk = new ErgoRosenChainSDK(
tokenMap, // TokenMap instance
lockAddress, // Lock address for bridge
undefined, // Optional: minimum box value (defaults to 400000n)
undefined, // Optional: transaction fee (defaults to 1000000n)
console, // Optional: new DummyLogger() or any logger
);Generate Lock Transactions
You can generate an unsigned lock transaction for bridging assets from Ergo to another chain:
const unsignedTx = await sdk.generateLockTransaction(
'tokenId', // Token ID on Ergo (e.g., 'erg' for native ERG)
NETWORKS.YOUR_TARGET_CHAIN, // Target chain (e.g., 'cardano')
'toAddress', // Recipient address on target chain
'fromAddress', // Sender's Ergo address
300_000_000n, // Unwwrapped Amount to bridge (in token's smallest unit)
3_000_000n, // Unwwrapped Bridge fee
1_000_000n, // Unwwrapped Network fee
utxoIterator, // Iterator or async iterator of available Ergo UTXOs
{
networkHeight: 1599000,
},
);
// The result is an object containing the unsigned transaction and related data.
console.log(unsignedTx.unsignedTxProxy);Constants and Types
The SDK exports several useful constants and types:
MIN_BOX_VALUE: Minimum value for an Ergo box (default: 400000n)FEE: Default transaction fee (default: 1000000n)- Types such as
UnsignedErgoTxProxy,UnsignedGenerateTxProxy, etc., are available for strong typing of transaction data.
Error handling
The SDK may throw the following error:
InsufficientAssetsException: Thrown if the provided UTXOs do not cover the required amount for the transaction.
Example:
import { InsufficientAssetsException } from '@ar-packages-changeit/sdk-ergo';
try {
// ... call generateLockTransaction ...
} catch (e) {
if (e instanceof InsufficientAssetsException) {
// Handle insufficient assets
} else {
throw e;
}
}Note:
- You must provide a realistic token configuration and valid lock address for your environment.
- Transaction signing are not handled by this SDK; you must provide UTXOs and sign the transaction as appropriate for your application.
