Giter VIP home page Giter VIP logo

spider-jockey's Introduction

Spider-Jockey

A simple program that emits Typescript classes based on provided JSON files, tested with truffle compilation output.

What does it generate?

It generates a class file that wraps around an ethers.Contract instance, and based on the generated ABI, it wraps each contract method in a corresponding typed method of that class, so you don't have to go blind when calling smart contract methods.

Example

Let's say that you have a contract called Some.sol:

contract Some {
  function getMagicNumberOf(address _addr) public view returns (uint256) {
    // Some illusory code here that does the magic
  }
}

This package will generate this class:

import ethers from "ethers";

class Some {
  constructor(private readonly contract: ethers.Contract) {}

  async getMagicNumberOf(_addr: string): number {
    // Some binding code here
  }
}

So you only have to do the magic of:

const contract = ...;// bind your contract
const some = new Some(contract);

const result = await some.getMagicNumberOf('some valid ethers address');

This makes the instance of some at least somewhat type-safe, and gives you intellisense hints when developing.

Contributing

If you know about a good Typescript code emitter that works with rust, I am looking forward to implement that also.

Edit: Since I couldn't find anything, and maintaining a code that does copy-and-paste of strings is tedious, I've built my own, but does only support the minimal for this program. During the following weeks I'll abstract that to an individual crate, so it can be reused.

Note

As you can imagine, this is not done yet. I'm currently not working in any Ethereum project (as of 2024), so if you want to use this library, and want it to be revived, open a PR or an issue. (But I imagine that noone is willing to use it anyway, but I'll be happy if you do)

There's a lot of things to enhance, like adding more parameters to the generator, here are some:

  • Where to output files
  • If output them in a single file with multiple export
  • Specify if the library is ethers or use a generic wrapper
    • That would make it more decoupled and customizable
    • Default implementation of that wrapper can be provided
  • Specify if the types are wrapped around DTOs
    • Addresses for instance could be wrapped, instead of using string
  • Specify if runtime checks are validated with 3rd party libraries
    • Like validating DTOs with class-validator
  • Specify further error handling
  • Use project files of some kind to configure the generator
    • Like a .spiderjockeyrc or spider-jockey.config.ron...

To name some. Any help is welcome.

spider-jockey's People

Contributors

sigmasoldi3r avatar

Watchers

James Cloos avatar  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.