GithubHelp home page GithubHelp logo

pinkdiamond1 / typechain-polkadot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from supercolony-net/typechain-polkadot

0.0 1.0 0.0 316 KB

License: MIT License

JavaScript 1.92% TypeScript 89.04% Handlebars 9.04%

typechain-polkadot's Introduction

created by sc

Overview 📄

Typechain was created by Supercolony to to improve developers’ experience working with ink! smartcontracts.

Nowadays, when technologies are growing faster and faster, we should think about optimizations of different routine processes and making older stuff better. One of these optimizations is to make code typesafe that will be flexible in different situations.

When a smart contract is being written, front-end developer receives file representation of it in the format called Application Binary Interface (ABI). One ABI per each contract, new ABI for every update of a contract.

Information about how to interact with a contract (methods names, arguments & returns types etc.) is included in this ABI file. It is not quite human-readable, so extraction of that information becomes a challenge. We need to have correct type definitions for each contract in TypeScript.

Interaction with blockchain is done with polkadot.js library, which only has abstract definitions for the contract in use, thus users' code cannot be typesafe. And Typechain-Polkadot can change it.

Installation & import

Install the package as dependency:

yarn add @supercolony/typechain-polkadot

Pass the folder with artifacts(in the example it is artifacts) as input argument and the output folder(in the example it is typed_contracts):

npx typechain-polkadot --in artifacts --out typed_contracts

Import the contract what you want to use(in the example it is my_psp22):

import MyPSP22 from "../typed_contracts/contracts/my_psp22"

In the code you can find all available methods and constructors.

Right now, you can't instantiate the contract via typechain(coming soon), but you can wrap any already deployed contract. If in the code you already have instantiated contract then you can easily wrap it:

const typed_contract = new MyPSP22(
    contract.address.toString(), 
    signer /* who will sign transactions*/, 
    contract.api
);

More information you can find in docs.

Usage of Typechain-compiler

npx typechain-compiler --config config.json

Also you can set some additional arguments like --noCompile, --noTypechain, --release

Config interface will be something like this:

export interface Config {
    projectFiles: string[]; // Path to all project files, everystring in glob format
    skipLinting : boolean; // Skip linting of project files
    artifactsPath : string; // Path to artifacts folder, where artifacts will be stored it will save both .contract and .json (contract ABI)
    typechainGeneratedPath : string; // Path to typechain generated folder
}

Project Details

Typesafe contracts' descriptions can be generated automatically by a script, taking a list of ABIs as an input, giving usable TS type definitions and even runtime code as its output.

Given, that a front-end developer needs to do this with every contracts update, such tool would save a lot of time and prevent mistakes of misusing smart contracts. It is installed as a package with built-in CLI.

When contracts descriptions come both with ABI and source code (*.contract files), our tool will provide means for deployment as well.

Roadmap 🚗

Typechain participates in the Web3 Grants, you can find the roadmap there:


Made with ❤️ by Supercolony

typechain-polkadot's People

Watchers

 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.