We are a team of smart contract developers, that previously worked a lot with EVM blockchains. There is a tool in EVM blockchains called "TypeChain". It simplifies development of client's code in many times by providing a simple interface to connect with blockchain, and eliminate errors such as wrong function name, etc.

So we wanted to help NEAR onboard this technology, and simplify access to contracts from front-end, back-end, scripts and tests. This would save developers time, as well as make their code more secure. We really like NEAR blockchain and we want to help it develop its infrastructure. We will surely use this tool in our next projects.

What it does

We created a similar to EVM's "TypeChain", tool on NEAR and called it "TypeGen";

The TypeGen tooling for NEAR developers, allows to speed-up the development of front-end, tests, scripts, back-end, in many times. Beyond it, it would eliminate human-prone errors in the code.

The "Near-TypeGen" tool allows programmers to: 1) Create ABI files from TypeScript contract's code; 2) Create TypeScript frontend functions from ABI files;

Feature - Problem Solved:

  1. Static typing - you will never call not existing method again;
  2. Boilerplate abstraction - native promises, safety checks and others;
  3. Compatibility - under the hood it uses near-api-js so it's fully compatible;

How we built it

We use ts-morph.ts for generating ABI definitions from NEAR contracts (Return Types, Function names, Parameter Types);

After parsing and finishing the work of part 1 of our tool - which is ABI generation - we enable the part 2 of our tool, - generation of frontend (client) code from the ABI files.

We do that through ready-to-onboard string templates, and we substitute types, function names, etc.

Challenges we ran into

  • How to generate ABI definitions from TypeScript contract's code;
  • How to generate TypeScript client's code, using calls & views on NEAR, from ABI definitions;

Accomplishments that we're proud of

We are proud that we created a tool for developers, that would speed-up the development of front-end side of any dApp using NEAR blockchain. Such a tool already existed for EVM chains, and we thought that it could be one step forward to building a convenient development infrastructure for NEAR.

It's a tool for developers, by developers;

What we learned

1) NEAR; 2) How Type Generation, Function Generation works in TypeScript; 3) How Code Analysis works with ts-morph.ts;

What's next for Near-TypeGen

We can't wait to see the feedback from NEAR, and we continue enhancing this tool. After discussing the feedback and enhancing the tool, we could onboard it into NEAR infrastructure. We already added this tool into "Hello-Near" example, and you can see it in the "examples" folder.

Built With

+ 11 more
Share this project: