[Ethereum] n API which allows to download source code of contracts

contract-debuggingdata-feedsexchange-apigo-ethereum

I am doing research into the security of smart contracts and was hoping to gather a dataset containing smart contract source codes. I was wondering if there is an API which allows this.

At etherscan you can use an API to get the smart contract ABI, but I'd like the source code. I give this as an example because all verified contracts of etherscan would be a great dataset.

My goal is to analyse these source codes to for instance categorize them based on a taxonomy or check how many of them contain certain patterns.

Best Answer

The web3 JS API has a getCode function that allows you to access the bytecode of the contract - that was deployed to the blockchain at the given address.

It should be possible to analyse this to determine common patterns in the code.

Since the source code, before it is compiled to bytecode, is not deployed to the blockchain it is not possible to retrieve it directly - which is why etherscan asks for it to be uploaded in order to verify it / show you the source code.

It might be possible to decompile / infer roughly the source code from the bytecode, but I am not aware of any tools which provide this functionality.

Related Topic