Code Monkey home page Code Monkey logo

jabi-evm's Introduction

JABI-EVM

codecov

This is a Java library to decode EVM functions and logs based on an ABI. There are other libraries like this one, just slightly different.

Installation

<!--    Add to your pom.xml repositories section-->
    <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>
<!--    Add the JABI-EVM dependency-->
    <dependency>
        <groupId>com.github.wkennedy</groupId>
        <artifactId>JABI-EVM</artifactId>
        <version>1.0.0</version>
    </dependency>

Decoding Functions:

    //Get the ABI as JSON (either from a file, web, etc...)
    String abiJson = new String(Files.readAllBytes(Paths.get("./src/test/resources/uniswap_abi.json")));
    
    //Get the raw input data from the transaction. See: https://etherscan.io/tx/0xde2b61c91842494ac208e25a2a64d99997c382f6aaf0719d6a719b5cff1f8a07
    String inputData = "0x18cbafe5000000000000000000000000000000000000000000000000000000000098968000000000000000000000000000000000000000000000000000165284993ac4ac00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000d4cf8e47beac55b42ae58991785fa326d9384bd10000000000000000000000000000000000000000000000000000000062e8d8510000000000000000000000000000000000000000000000000000000000000002000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
    //Create the Decoder and add the ABI (there are various ways to do this based on your needs. ABIs can be mapped to contract addresses and stored on the Decoder)
    Decoder decoder = new Decoder();
    decoder.addAbi("0x7a250d5630b4cf539739df2c5dacb4c659f2488d", abiJson);
    //Decode the function.
    DecodedFunctions decodedFunctions = decoder.decodeFunction(inputData);

Decoding Logs:

    //Get the ABI as JSON (either from a file, web, etc...)
    String abiJson = new String(Files.readAllBytes(Paths.get("./src/test/resources/log_test_abi.json")));

    //Instantiate a Decoder with the ABI
    Decoder decoder = new Decoder(abiJson);
    //Create the logs to decode
    List<String> topics = new ArrayList<>();
    topics.add("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef");
    topics.add("0x00000000000000000000000066f044b68f2808753b99a7d31820fbc751342d9c");
    topics.add("0x0000000000000000000000004056140bc49cb36dd0b5bc4b4530ef56781cc365");
    Log log = new Log("0x00000000000000000000000000000000000000000000000003aa8e4f70c34000",
            topics,
            "0x4056140BC49cb36dd0b5bC4b4530ef56781Cc365");
    Log[] logs = new Log[]{log};
    //Decode the logs
    List<DecodedLog> result = decoder.decodeLogs(logs);

jabi-evm's People

Contributors

wkennedy avatar

Stargazers

 avatar

Watchers

Lucian avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.