Is it possible to get the ABI of a known contract address without the source code? The only way I've found is by using etherscan's API, but it only works for verified contracts. Any help is appreciated, thanks!
Is it possible to get the ABI of a known contract address without the source code? The only way I've found is by using etherscan's API, but it only works for verified contracts. Any help is appreciated, thanks!
Simple Answer: No
Long Answer: Maybe. The ABI is generated from the source code, but if you know what the functions are, you can "create" the ABI yourself.
The ABI of a contract stands for the application binary interface, and it just defines how to interact with a smart contract.
For example, maybe you don't know what the source code of a contract is, but you know it has a transfer function. You could "make" the ABI as little as:
[
{
"constant":false,
"inputs":[
{"name":"_to","type":"address"},
{"name":"_value","type":"uint256"}
],
"name":"transfer",
"outputs":[
{"name":"success",
"type":"bool"}
],
"payable":false,
"stateMutability":"nonpayable",
"type":"function"
}
]
Or with a compiled interface, since a compiled interface will output an ABI.
pragma solidity ^0.8.8;
interface ContractInterface {
function transfer(address to, uint256 value) external returns (bool success);
}
Since ABIs and Interfaces don't have to encompass every single function a smart contract is capable of.
Additionally, there are such things as Decompilers which attempt to decompile byte code to figure out what the contract is, with that you could get the ABI.
I guess you want the ABI to call functions on the contract,
You can still interact with contracts without the ABI, if you know the function signature of the function you want to call:
let test = await provider.call({
// contract we want to talk to
to: address,
// `function name() view returns (string)`
data: "0x313ce567",
});
console.log(`Decimals: ${test}`)
Decimals: 0x0000000000000000000000000000000000000000000000000000000000000009
The ABI JSON is generated from the source code. So unless you know the source code, there's no source to generate the ABI JSON from.