You can use the Etherscan API. They have an endpoint that will let you get a specified contracts ABI. You need to sign up and get an api key before you can start sending requests but it is free. The contract also needs to be verified for this to work.
Once you have signed up, assuming you're using c#, you could get the ABI using this code:
var client = new HttpClient();
var contractAddress = "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413";
var apiKey = "My-Api-Key";
using (client)
{
var abiResponse = await client.GetAsync($"https://api.etherscan.io/api?module=contract&action=getabi&address={contractAddress}&apikey={apiKey}");
var contractAbi = await abiResponse.Content.ReadAsStringAsync();
}
You could do the same using js.
const https = require('https');
const contractAddress = "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413";
const apiKey = "your-api-key";
const endpoint = `/api?module=contract&action=getabi&address=${contractAddress}&apikey=${apiKey}`;
var options = {
host: 'api.etherscan.io',
path: endpoint,
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
};
async function getContractAbi() {
let request = https.get(options, (res) =>
{
if (res.statusCode !== 200) {
console.error(`Did not get an OK from the server. Code:
${res.statusCode}`);
res.resume();
return;
}
let data = '';
res.on('data', (chunk) => { data += chunk; });
res.on('close', () =>
{
console.log('Retrieved all data');
console.log(data);
});
});
request.on('error', (err) => { console.error(`Encountered an error trying to
make a request: ${err.message}`); });
}
getContractAbi();