Solidity Generic Contract Call

[Solved] Solidity Generic Contract Call | Solidity - Code Explorer | yomemimo.com
Question : solidity generic contract call

Answered by : xlassix-xx

//args= list of data structures the function takes like ["address","uint"]
// if you are unsure you can type you can 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();

Source : | Last Update : Tue, 23 Aug 22

Answers related to solidity generic contract call

Code Explorer Popular Question For Solidity