xxxxxxxxxx
// please note the length of args the function takes must be known
// args is a list of data structure the function takes
// example: ["address","bool"]
// if you are unsure of the type use "int"
const genericABIGenerator = (
args,
function_name,
returnType = "int"
) => {
return [
{
inputs: args.map((value, index) => ({
name: `arg${index}`,
type: value ?? "int",
})),
name: function_name,
outputs: [
{
name: "output",
type: returnType,
},
],
stateMutability: "view",
type: "function",
},
];
};
//code execution
const contract = new client.eth.Contract(
genericABIGenerator(inputTypeList, function_name, outputType),
contractAddress
);
const result = await contract.methods[function_name](args).call();