import { createOtimClient } from "@otim/sdk";
import { privateKeyToAccount } from "viem/accounts";
import { sepolia } from "viem/chains";
import { http, parseEther } from "viem";
async function main() {
// initialize the client
const account = privateKeyToAccount("0x...");
const client = createOtimClient({
chain: sepolia,
transport: http(),
walletAccount: account,
});
// authenticate with siwe
const loginResponse = await client.auth.login({
address: account.address,
chainId: sepolia.id,
});
// add token to requests
await client.auth.setAuthorizationHeader(loginResponse.authorization);
// get gas fee estimate
const feeEstimate = await client.config.getMaxPriorityFeeEstimate({
chainId: sepolia.id,
});
const priorityFee = BigInt(feeEstimate.normalMaxPriorityFeeEstimate);
// build transfer instruction
const transferBuild = await client.instruction.build.transfer({
target: "0x742d35Cc6343C4532F1f4e8d7C0c65c0c7d3d2E8",
value: parseEther("0.1"),
fee: {
token: "0x0000000000000000000000000000000000000000", // eth for fees
maxPriorityFeePerGas: priorityFee,
},
});
// activate the instruction
const transferResult = await client.instruction.activate({
instruction: transferBuild.instruction,
actionType: transferBuild.actionType,
nickname: "eth transfer to recipient",
});
console.log(`Transfer activated: ${transferResult.instructionId}`);
// logout
await client.auth.logout();
}
main().catch(console.error);