Combine Para’s embedded wallets with M0’s programmable stablecoin infrastructure
Install packages
npm install @getpara/server-sdk@alpha @getpara/viem-v2-integration@alpha viem@^2
Import dependencies
import { ParaServer } from "@getpara/server-sdk@alpha"; import { createParaViemClient, createParaAccount } from "@getpara/viem-integration@alpha"; import { http } from 'viem'; import { mainnet } from 'viem/chains';
Initialize Para SDK
const para = new ParaServer(process.env.PARA_API_KEY);
Create wallet
const hasWallet = await para.hasPregenWallet({ pregenId: { email: 'user@example.com' }, }); let pregenWallet; if (!hasWallet) { pregenWallet = await para.createPregenWallet({ type: 'EVM', pregenId: { email: "user@example.com" }, }); }
Create Para account and client
const account = await createParaAccount(para); const client = createParaViemClient(para, { account, chain: mainnet, transport: http(), });
const M_ADDRESS = '0x866A2BF4E572CbcF37D5071A7a58503Bfb36be1b'; const WM_ADDRESS = '0x437cc33344a0B27A429f795ff6B469C72698B291';
const ERC20_ABI = [ { name: 'approve', type: 'function', inputs: [{ name: 'spender', type: 'address' }, { name: 'amount', type: 'uint256' }], outputs: [{ type: 'bool' }] }, { name: 'transfer', type: 'function', inputs: [{ name: 'recipient', type: 'address' }, { name: 'amount', type: 'uint256' }], outputs: [{ type: 'bool' }] } ]; const WM_ABI = [ { name: 'wrap', type: 'function', inputs: [{ name: 'recipient', type: 'address' }, { name: 'amount', type: 'uint256' }], outputs: [{ type: 'uint240' }] }, { name: 'unwrap', type: 'function', inputs: [{ name: 'recipient', type: 'address' }, { name: 'amount', type: 'uint256' }], outputs: [{ type: 'uint240' }] } ];
Approve $M tokens
async function wrapMToWM(amount) { const approveHash = await client.writeContract({ address: M_ADDRESS, abi: ERC20_ABI, functionName: 'approve', args: [WM_ADDRESS, amount] }); console.log('Approve hash:', approveHash);
Wrap tokens
const wrapHash = await client.writeContract({ address: WM_ADDRESS, abi: WM_ABI, functionName: 'wrap', args: [account.address, amount] }); console.log('Wrap hash:', wrapHash); }
async function unwrapWMToM(amount) { const unwrapHash = await client.writeContract({ address: WM_ADDRESS, abi: WM_ABI, functionName: 'unwrap', args: [account.address, amount] }); console.log('Unwrap hash:', unwrapHash); }
async function transferToken(tokenAddress, recipient, amount) { const transferHash = await client.writeContract({ address: tokenAddress, abi: ERC20_ABI, functionName: 'transfer', args: [recipient, amount] }); console.log('Transfer hash:', transferHash); }
await wrapMToWM(1000000n); await unwrapWMToM(1000000n); await transferToken(M_ADDRESS, '0xRecipientAddress', 1000000n);