Support for ABI format like Ethers #4001
Verified answer
by
jxom
ArielGueta
asked this question in
Question
-
|
Hi, I don't find in the docs how we can get the same functionality in this library as we can with Ethers: import { utils } from "ethers";
const iface = new utils.Interface([
{
type: "function",
name: "placeOrder",
stateMutability: "nonpayable",
inputs: [
{
name: "order",
type: "tuple",
components: [
{ name: "id", type: "uint256" },
{ name: "buyer", type: "address" },
{ name: "seller", type: "address" },
{ name: "amount", type: "uint256" },
],
},
],
outputs: [{ name: "", type: "bool" }],
},
{
type: "function",
name: "batchOrders",
stateMutability: "nonpayable",
inputs: [
{
name: "orders",
type: "tuple[]",
components: [
{ name: "id", type: "uint256" },
{ name: "buyer", type: "address" },
{ name: "seller", type: "address" },
{ name: "amount", type: "uint256" },
],
},
],
outputs: [{ name: "", type: "uint256" }],
},
]);
// get function fragment
const fn = iface.getFunction("placeOrder");
console.log(fn.format("full"));
// -> "function placeOrder(tuple(uint256 id, address buyer, address seller, uint256 amount) order) returns (bool)" |
Beta Was this translation helpful? Give feedback.
Admin verified this answer by
jxom
Nov 21, 2025
Replies: 1 comment 2 replies
-
|
I would recommend our other library import { AbiFunction } from 'ox'
const fn = AbiFunction.fromAbi(abi, 'placeOrder')
const string = AbiFunction.format(fn) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would recommend our other library
oxfor this. Viem uses it under-the-hood.