Hot answers tagged

10

If you use solc --ast, the compiler will output a json-representation of the AST (this is also included in the npm version of the compiler). Is that enough for your purposes? If not, please come to gitter to discuss.


9

There's a file called grammar.txt in the Solidity repo: https://github.com/ethereum/solidity/blob/develop/docs/grammar.txt That's probably what you're looking for?


9

I implemented a bitcoin blockchain parser after following along with this blog post. I havent tried changing it to work with the Ethereum blockchain but maybe it can give you some guidance. Here's a parser implemented in Go to hopefully give you some Ethereum specific examples to go off of.


7

The length of the string is the word after the one you have identified as status. So for asset1 it is 0x16 = 22 in decimal, and for asset2 it is 0xc9 = 201 decimal. Strings are dynamic types and have a particular ABI representation as described in the ABI spec. Dynamic data appears after the rest of the data: your string_content ??? word is a pointer to ...


7

I wrote an ANTLR4 grammar for Solidity that you may find useful: https://github.com/solidityj/solidity-antlr4 It can generate parsers in any of the ANTLR supported targets and it has full support for the Solidity language as of today.


6

You can find the parser's source code in the ethereum/solidity project, it's written in C++. Here's the main implementation file: Parser.cpp You can find the main repo where solidity is linked and which contains the required dependencies to build it in the webthree-umbrella project repo. Here's a direct link to the wiki for installing it, you don't need ...


3

In addition to chriseth's answer, there's also the solidity-parser project which is useful if you A) are developing in a Javascript context, or B) don't want the parser to error if there are unresolved imports (unfortunately solc --ast will error if there are imports it cannot find).


2

Here's yet another link pointing to the solidity documentation: http://solidity.readthedocs.io/en/develop/miscellaneous.html#language-grammar


2

If you want to do it in NodeJs, you can create a file named decodeParams.js and which contains: #!/usr/bin/nodejs const Web3 = require("web3"); const web3 = new Web3(); const Coder = require("./node_modules/web3/lib/solidity/coder.js"); var result = Coder.decodeParams( [ "uint256", "uint256", "uint256", "address", "string" ], "...


2

Try this out. pragma solidity > 0.5.1; contract Test { function test() public view returns (string memory) { return addressToString(address(this)); } function addressToString(address _addr) public pure returns(string memory) { bytes32 value = bytes32(uint256(_addr)); bytes ...


1

Smart contract code (EVM bytecode, in the case of Ethereum) is "uploaded" to the blockchain in the deployment transaction of a smart contract. The contract gets its own address, similar to Ethereum personal address. You can easily inspect transactions in and out of a smart contract by monitoring its address. This can be done using a blockchain explorer like ...


1

You can try QuickBlocks. It's C++, not Python, but it fully supported and actively developed: https://github.com/Great-Hill-Corporation/quickBlocks


1

Here is a tool that takes an ABI and convert it to its Solidity interface: https://bia.is/tools/abi2solidity/ Source code is published on GitHub: https://github.com/maxme/abi2solidity/


1

grabABI, which is part of QuickBlocks, comes very close. It's open source, so you could modify it slightly to surround its output with the contract part and add the squiggles after each function, but it should be easy. You can find it on github.


1

Well, I found the answer myself... just a juxtaposition of fields like this, in PHP code: list($_field1, $_field2, $_field3, $_zeros, $_field4, $_field5) = sscanf($output, "0x%64s%64s%64s%24s%40s%s"); $_field1 = hexdec($_field1); $_field2 = hexdec($_field2); $_field3 = hexdec($_field3); $_field4 = '0x' . $_field4; $_field5 = hexstr($_field5); echo "\n<hr&...


1

You can use ConsenSys/solidity-parser and walk the resulting AST looking for variable declarations. There are no visitors included in the package, so you will have to write one yourself.


1

There is also a xText grammar, https://github.com/webdaford/smart-contract-tools/blob/master/workspace/com.dell.research.bc.eth.solidity.editor/src/com/dell/research/bc/eth/solidity/editor/Solidity.xtext which is quite similar to BNF.


1

is ethereumjs-tx-unsign along the lines of what you're hoping to accomplish? if so.. and you're also interested in obtaining even more information (from the signature), then the unsign() function in ethereumjs-tx-sign is a good place to look.


1

It perhaps doesn't meet the "it would be nice to give it to someone non-technical and allow them to parse it without using tools I've provided" qualifier, but the Ethslurp tool may be of use to people with at least some technical knowhow. (As mentioned in an answer to this very similar previous question: Symbolic decoding of a transaction for Solidity.)


1

Your geth node will also act as a JSON-RPC server. You can use the APIs wiki page to crawl the blockchain and extract block data. Here is an interesting git repo that you could fork. It's a bit show though and requires some code modifications as the owner isn't maintaining it any more. You'll find a pull request on that repo that runs substantially faster, ...


1

In addition to Tim's answer there's also a python-solidity-parser based on the ANTLR syntax and AST format used in solidity-parser-antlr that you can use if you want to avoid depending on the compiler. Note: compiler AST is the truth.


Only top voted, non community-wiki answers of a minimum length are eligible