Docs/Sdk Reference
SDK Reference
TypeScript SDK for interacting with AutoLoop smart contracts using viem.
Installation
npm install @luckymachines/autoloop-sdk viemThe SDK is published to the Lucky Machines registry at packages.luckymachines.io.
Quick Start
import { createPublicClient, http } from "viem";
import { sepolia } from "viem/chains";
import {
getAutoLoopContract,
getRegistryContract,
} from "@luckymachines/autoloop-sdk";
const client = createPublicClient({
chain: sepolia,
transport: http(),
});
const autoLoop = getAutoLoopContract(client);
const balance = await autoLoop.read.balance(["0xYourContract..."]);
const registry = getRegistryContract(client);
const contracts = await registry.read.getRegisteredAutoLoops();Contract Factories
getAutoLoopContract(client, chainId?)
const autoLoop = getAutoLoopContract(publicClient);
await autoLoop.read.balance([contractAddress]);
await autoLoop.read.maxGasFor([contractAddress]);
await autoLoop.read.maxGasPriceFor([contractAddress]);
await autoLoop.read.gasBuffer();
await autoLoop.read.baseFee();getRegistryContract(client, chainId?)
const registry = getRegistryContract(publicClient);
await registry.read.getRegisteredAutoLoops();
await registry.read.getRegisteredControllers();
await registry.read.isRegisteredAutoLoop([contractAddress]);
await registry.read.isRegisteredController([controllerAddress]);getRegistrarContract(client, chainId?)
const registrar = getRegistrarContract(walletClient);
await registrar.write.registerAutoLoopFor([contractAddress, maxGas]);
await registrar.write.deposit([contractAddress], {
value: parseEther("0.1"),
});
await registrar.write.requestRefundFor([contractAddress]);
await registrar.write.registerController([], {
value: parseEther("0.001"),
});Deployment Addresses
import { getDeployment, DEPLOYMENTS } from "@luckymachines/autoloop-sdk";
const sepolia = getDeployment(11155111);
console.log(sepolia.AUTO_LOOP);
console.log(sepolia.AUTO_LOOP_REGISTRY);
console.log(sepolia.AUTO_LOOP_REGISTRAR);| Chain | ID | Status |
|---|---|---|
| Mainnet | 1 | Deployed |
| Sepolia | 11155111 | Deployed |
| Anvil | 31337 | Development |
ABIs
import {
autoLoopABI,
autoLoopRegistryABI,
autoLoopRegistrarABI,
autoLoopCompatibleInterfaceABI,
} from "@luckymachines/autoloop-sdk";Listen for Loop Events
import { createPublicClient, http, parseAbiItem } from "viem";
import { mainnet } from "viem/chains";
import { getDeployment } from "@luckymachines/autoloop-sdk";
const client = createPublicClient({
chain: mainnet,
transport: http(),
});
const deployment = getDeployment(1);
const unwatch = client.watchEvent({
address: deployment.AUTO_LOOP,
event: parseAbiItem(
"event AutoLoopProgressed(address indexed autoLoopAddress, uint256 indexed timestamp, address controller, uint256 gasUsed, uint256 gasPrice, uint256 gasCost, uint256 fee)"
),
onLogs: (logs) => {
for (const log of logs) {
console.log("Loop progressed:", log.args);
}
},
});Register & Fund a Contract
import { createWalletClient, http, parseEther } from "viem";
import { mainnet } from "viem/chains";
import { getRegistrarContract } from "@luckymachines/autoloop-sdk";
const wallet = createWalletClient({
chain: mainnet,
transport: http(),
});
const registrar = getRegistrarContract(wallet);
// Register with 500k max gas
await registrar.write.registerAutoLoopFor(["0xYourContract...", 500000n]);
// Fund with 0.5 ETH
await registrar.write.deposit(["0xYourContract..."], {
value: parseEther("0.5"),
});