Skip to content

How to determine whether an address is a contract address #3084

Answered by novaknole
linxianxi asked this question in Q&A
Discussion options

You must be logged in to vote

Super simple..

try {
    const code = await provider.getCode(address);
    if (code !== '0x') return true;
  } catch (error) {}
// if it comes here, then it's not a contract.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@linxianxi
Comment options

@ricmoo
Comment options

@crazyrabbitLTC
Comment options

Answer selected by ricmoo
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants