'how can i call a function in a smart contract from an abi json file smart contract

i have the abi json file for a contract and i want to use its functions in my smart contract. is there any way to do it?

for example i have a contractA.sol and contractB.jsonn in my contractA i want to call a function fncA in the contractB, but contractB is elready deployed and i just have its abi file. i imported the json file to my contract but then i don't know how to fetch its functions and use them.

import '../abis/contractB.json'
contract contractA {
.
.
.
// i want to use funcA from contractB contract here.
.
.
.
}


Solution 1:[1]

Unfortunately solidity doesn't supports using json ABIs as interface.

You can use some tools like this https://gnidan.github.io/abi-to-sol/ to generate the interface, then copy it into a 'IContractB.sol` file, which can be imported in your 'ContractA.sol'.

Solution 2:[2]

yes you can do it in a very few steps. just use the abi of a particular function and paste it in a new abi of a smart contract on which your are currently working and call that method just using web3.

please reply if you have any queries.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RiccardoS
Solution 2 Nikhil Chauhan