5

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.

4

I have recently created an unoffical python library and scriptable cli for etherchain.org called pyetherchain that gives you access to submitted solidity contract source-code including (experimental) abi-decoded constructor arguments/transactions. The abi-decoded inputs help you understand how contracts/people are interacting with the smart contract.

install and start: python -m pip install pyetherchain; python -m pyetherchain

Example: download_contracts.py

Here's some funny things I discovered with this (check the comment header block for abi-decoded transactions 👍) enter image description here

3

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.

  • This was crazy difficult to find in the docs. TY! – meawoppl Nov 4 '17 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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