Skip to main content

Contract Method Call

To call a given method of a contract use the call method of LocalRPCSubscriber class.

import { Sheet, SheetProxy } from "@okcontract/cells";
import {
MultiChainRPC,
LocalRPCSubscriber,
Address,
type EVMAddress,
} from "@okcontract/multichain";

const sheet = new Sheet();
const proxy = new SheetProxy(sheet);
const multi = new MultiChainRPC(proxy);
const local = new LocalRPCSubscriber(proxy, multi);

const abi = proxy.new(erc20Abi as Abi);
const usdcContract = proxy.new<EVMAddress<"evm">>(
{
addr: new Address("0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238"),
chain: "sepolia",
ty: "c",
},
"usdcContract"
);
const balance = rpc.call(
usdcContract, // the contract
abi, // the abi
proxy.new("balanceOf"), // method
proxy.new(new Address("0xa889C78f474a98ce667Db5206f35A9a14e3e027a")) // owner
);