Modern, lightweight TypeScript SDK for building on the Umi Network with Viem integration. Open-source, modular, and developer-friendly.
- 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
npm install uiem
# or
yarn add uiem
import { createPublicClient,createWalletClient } from 'uiem';
const publicClient = createPublicClient();
const walletClient = createWalletClient();
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);
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);
import { serializer } from 'uiem';
const rawCalldata = '0xa9059cbb...';
const serialized = serializer(rawCalldata);
console.log('Serialized:', serialized);
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 });
You can use uiem's BCS serialization utilities in your Hardhat deployment scripts for Umi Network compatibility.
npm install uiem
# or
yarn add uiem
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.
- 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.
See src/example/index.ts
for a full working example.
- Fork the repo and create your branch
- Run
npm install
- Make your changes and add tests/examples
- Run
npm run build
andnpm test
- Submit a pull request!
MIT © Defiboy