Skip to content

Instantly share code, notes, and snippets.

@anonymoussprocket
Created July 21, 2022 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymoussprocket/e3b7992604cfefaa419dd60f54d3f876 to your computer and use it in GitHub Desktop.
Save anonymoussprocket/e3b7992604cfefaa419dd60f54d3f876 to your computer and use it in GitHub Desktop.
Mock a mainnet contract dynamically
import fetch from 'node-fetch';
import { smock } from '@defi-wonderland/smock';
async function deployMockContractFromAddress(contractAddress: string, etherscanKey: string) {
const abi = await fetch(`https://api.etherscan.io/api?module=contract&action=getabi&address=${contractAddress}&apikey=${etherscanKey}`)
.then(response => response.json())
.then(data => JSON.parse(data['result']));
return smock.fake(abi, {address: contractAddress});
}
@anonymoussprocket
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment