Skip to content

TypeScript SDK

Installation

bun add @unionlabs/client

The Union Client is TypeScript-first and framework agnostic. At app.union.build we use Svelte but you can use any framework or no frameworks at all. If you’re a React developer, checkout this demo on Stackblitz.

Client Initialization

import { privateKeyToAccount } from "viem/accounts"
import { createUnionClient, http } from "@unionlabs/client"
const client = createUnionClient({
chainId: "80084",
transport: http("https://bartio.rpc.berachain.com"),
account: privateKeyToAccount(`0x${process.env.PRIVATE_KEY}`),
})

Transferring Assets

We will transfer 1 HONEY from Berachain bArtio to Stride Testnet.

You have the option to trigger the approval transaction manually by setting autoApprove to false then calling .approveTransaction before calling .transferAsset.

import { unionClient } from "./client.ts"
import type { TransferAssetsParameters } from "@unionlabs/client"
const transferPayload = {
amount: 1n,
autoApprove: false,
// ^ we will approve manually for this example
destinationChainId: "stride-internal-1",
receiver: "stride17ttpfu2xsmfxu6shl756mmxyqu33l5ljegnwps",
denomAddress: "0x0E4aaF1351de4c0264C5c7056Ef3777b41BD8e03",
// ^ HONEY contract address
} satisfies TransferAssetsParameters<"80084">
const approval = await unionClient.approveTransaction(transferPayload)
if (approval.isErr()) {
console.error(approval.error)
process.exit(1)
}
console.info(`Approval hash: ${approval.value}`)
const transfer = await unionClient.transferAsset(transferPayload)
if (transfer.isErr()) {
console.error(transfer.error)
process.exit(1)
}
console.info(`Transfer hash: ${transfer.value}`)

Run the above example

PRIVATE_KEY="" bun x tsx main.ts