Skip to content

defiboyszn/uiem

Repository files navigation

Uiem SDK

Modern, lightweight TypeScript SDK for building on the Umi Network with Viem integration. Open-source, modular, and developer-friendly.

GitHub License: MIT


Features

  • TypeScript-first: Full type safety and modern developer experience
  • Viem Integration: Leverages the viem toolkit for Ethereum and L2s
  • Custom Actions: Easily extend clients with uiem-specific contract actions
  • BCS Serialization: Built-in support for Umi Network's BCS-encoded contract calls
  • Modular: Use only what you need—public client, wallet client, serialization, and more
  • Open Source: MIT licensed and open to contributions

Installation

npm install uiem
# or
yarn add uiem

Quick Start

import { createPublicClient,createWalletClient } from 'uiem';

const publicClient = createPublicClient();
const walletClient = createWalletClient();

API Usage

1. Public Client (Read-Only)

import { createPublicClient } from 'uiem';
import { Abi } from 'viem';

const erc20Abi: Abi = [/* ... */];
const contractAddress = '0x...';
const userAddress = '0x...';

const publicClient = createPublicClient();

// Prepare calldata for a contract read
const calldata = publicClient.getFunction('balanceOf', erc20Abi, contractAddress, [userAddress]);

// Call the contract (read-only)
const result = await publicClient.callFunction({
  to: calldata.to,
  data: calldata.data,
});
console.log('Balance:', result);

2. Wallet Client (Write)

import { createWalletClient } from 'uiem';
import { devnet } from 'uiem/chain';

const walletClient = createWalletClient({ chain: devnet });

// Prepare calldata for a contract write (e.g., transfer)
const transferCalldata = publicClient.getFunction('transfer', erc20Abi, contractAddress, [userAddress, '1000000000000000000']);

// Send a transaction (requires wallet connection)
const tx = await walletClient.uiemWriteContract({
  to: transferCalldata.to,
  data: transferCalldata.data,
  // account: ... // Optionally specify account
  // value: 0n // Optionally send ETH
});
console.log('Transaction result:', tx);

Advanced Usage

BCS Serialization

import { serializer } from 'uiem';

const rawCalldata = '0xa9059cbb...';
const serialized = serializer(rawCalldata);
console.log('Serialized:', serialized);

Custom Chains

You can use your own chain configuration:

import { defineChain } from 'viem';

const customChain = defineChain({
  id: 12345,
  name: 'MyChain',
  nativeCurrency: { name: 'ETH', symbol: 'ETH', decimals: 18 },
  rpcUrls: { default: { http: ['https://mychain-rpc.com'] } },
});

const client = createPublicClient({ chain: customChain });

Hardhat Deployment with uiem

You can use uiem's BCS serialization utilities in your Hardhat deployment scripts for Umi Network compatibility.

Installation

npm install uiem
# or
yarn add uiem

Usage Example

import { serialize } from 'uiem/hardhat';
import { ethers } from 'hardhat';

async function main() {
  // Compile your contract and get the bytecode
  const MyContract = await ethers.getContractFactory('MyContract');
  const bytecode = MyContract.bytecode;

  // Serialize the bytecode for Umi Network deployment
  const serializedBytecode = serialize(bytecode);
  console.log('Serialized bytecode:', serializedBytecode);

  // You can now use serializedBytecode in your deployment transaction
  // ...
}

main().catch(console.error);
  • The serialize function wraps and encodes your contract bytecode for Umi Network deployment.
  • You can also use this utility for function call data if needed.

Type Definitions

  • uiemPublicClient: Public client with uiem custom actions (getFunction, callFunction)
  • uiemWalletClient: Wallet client with uiem custom actions (uiemWriteContract)

Types are available in the source and can be imported from the relevant modules.


Example

See src/example/index.ts for a full working example.


Contributing

  1. Fork the repo and create your branch
  2. Run npm install
  3. Make your changes and add tests/examples
  4. Run npm run build and npm test
  5. Submit a pull request!

License

MIT © Defiboy


Links

About

The modern, lightweight TypeScript SDK for building on Umi Network with Viem integration.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published