1

Is there a way to analyze a token contract and determine if it was created using Create2?

2
  • You can do a debug trace on the transaction that deployed the contract. However it is advanced technique and you need deep EVM insight to know how to do it. Commented Oct 7, 2023 at 15:51
  • this is something I'd be willing to provide compensation for if someone could help me look at 2 addresses Commented Oct 7, 2023 at 17:05

1 Answer 1

4
const ethers = require("ethers");

(async () => {

  const provider = new ethers.JsonRpcProvider("YOUR_PROVIDER");

  const response = await provider.send("debug_traceTransaction", ["TX_HASH",{"tracer": "callTracer"},]);
  
  const calls = response.calls || [];
  const hasMatchingObject = calls.some(item => {
    return item.type === "CREATE2" && item.to === "CONTRACT_ADDRESS";
  });
  hasMatchingObject ? console.log("Create2") : console.log("No create2");

})();

This does what you need (it logs "create2" if the contract at CONTRACT_ADDRESS was created using create2 and "no create2" otherwise).

Here's how to run it (skip if you know)

install node.js.

create a new folder In this folder on a terminal window, run npm init (skip through everything its gonna ask you), then npm install ethers.

Still in this folder, create a .js file (name it as you want), paste this in it, (make sure to replace YOUR_PROVIDER, TX_HASH and CONTRACT_ADDRESS with the relevant values), then save it.

In your terminal window from earlier, run node yourfilename.js It's gonna return what i previously said.

My 0x address is in my bio if you wanna send something, but you don't have to, this took me 5 minutes and a google search.


EDIT (see comments) : On an etherscan contract page (etherscan.io/address/... not etherscan.io/token/..., those only show stats about a token), there is a 'contract creator', field. You can see the contract deployment transaction from here. If the transactions to field displays " ['address' Created], (like here) that means the contract was deployed directly from an EoA, and that it wasnt using create2. If the to field is just a contract address, without any mention of a contract creation (like here), that means the contract was deployed by another contract, in that case go to the 'Internal Txns' tab, if you see a line with create2_X_X_X there, that means create2 was used. If you see create_X_X_X, that means it wasnt.

8
  • ( alternatively if you don't wanna install anything you can try and run the code in an online sandbox like codesandbox.io )
    – Foxxxey
    Commented Oct 7, 2023 at 18:13
  • Hey! Thanks so much for taking the time to share this. I'm getting sort of a strange error on my end: code: 'UNSUPPORTED_OPERATION', operation: 'debug_traceTransaction', info: { error: { code: -32601, message: 'The method debug_traceTransaction does not exist/is not available' }, payload: { method: 'debug_traceTransaction', params: [ '0x4b37d2f343608457ca3322accdab2811c707acf3eb07a40dd8d9567093ea5b82', { tracer: 'callTracer' } ], id: 2, jsonrpc: '2.0' } } But will keep troubleshooting Commented Oct 8, 2023 at 18:29
  • I think this is because I don't have a paid plan on Infura or anywhere else, so I am out of luck. thank you anyway! Commented Oct 8, 2023 at 18:46
  • That's probably why yeah. If you're on ETH mainnet use a demo endpoint. docs-demo.quiknode.pro works . (obviously it will only work a few times, so if you need to do that often you'll need a paid plan somewhere)
    – Foxxxey
    Commented Oct 8, 2023 at 19:33
  • (or run a light node)
    – Foxxxey
    Commented Oct 8, 2023 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.