Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pin polkadot versions #136

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: tests

on:
pull_request:
branches: [main]
paths:
- 'packages/**'
- '.github/workflows/tests.yml'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always
GH_TOKEN: ${{ github.token }}
NODE_ENV: test

jobs:
check:
runs-on: ubuntu-latest
steps:
# Checkout the repo
- uses: actions/checkout@v3

- run: npm install -g [email protected]
- run: npm install

# build all packages in workspace
- run: npm run build:all
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,4 @@ node_modules
/dist
lerna-debug.log

package-lock.json
yarn.lock

/wip
50 changes: 6 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,21 @@
<div align="center">
<a href="https://patron.works/">
<img src="https://github.com/Brushfam/patron-backend/raw/master/Patron.png" alt="Logo" >
</a>
# Typechain-Polkadot
This library generates TypeScript types from an `ink!`-based smart contract.

<p align="left">
&#128226; &#128226; &#128226; We are thrilled to announce <a href="https://patron.works/">Patron</a>, which brings smart contract verification functionality to the Polkadot ecosystem. &#128226; &#128226; &#128226;
</p>
</div>

> Smart contract verification ensures the security, reliability, and trustworthiness of dApps and blockchain platforms. With [Patron](https://patron.works/), you can simplify the deployment flow, manage your builds and make the Polkadot ecosystem more secure and transparent.
<br/>
So, in other words, <a href="https://patron.works/">Patron</a> is an all-in-one contracts platform, which allows you to build and verify ink! smart contracts inside of an isolated environment, explore contract verification details.

![Typechain](https://user-images.githubusercontent.com/88630083/218826097-0d3d4f61-a028-45a9-a91d-1f245c4663ea.png)

![GitHub](https://img.shields.io/github/license/727-ventures/typechain-polkadot)

If you have any questions regarding Typechain-Polkadot, you can join the [Brushfam Element channel](https://matrix.to/#/!utTuYglskDvqRRMQta:matrix.org?via=matrix.org&via=t2bot.io&via=web3.foundation) to find your answers and meet other ink! smart contracts developers.

### Latest releases:
- Typechain-Polkadot [![npm version](https://badge.fury.io/js/@727-ventures%2Ftypechain-polkadot.svg)](https://badge.fury.io/js/@727-ventures%2Ftypechain-polkadot)
- Typechain-Compiler [![npm version](https://badge.fury.io/js/@727-ventures%2Ftypechain-compiler.svg)](https://badge.fury.io/js/@727-ventures%2Ftypechain-compiler)
- Typechain-Types [![npm version](https://badge.fury.io/js/@727-ventures%2Ftypechain-types.svg)](https://badge.fury.io/js/@727-ventures%2Ftypechain-types)
## Overview :page_facing_up:

Typechain is maintained by [Brushfam](https://www.brushfam.io/) team to improve developers’ experience working with ink! smart contracts.

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.
# NOTE
This library is a modified version of 727-venture's typechain-polkadot library. Our team at prosopo is currently in the process of revamping the library to incorporate bug fixes, updates from polkadot libraries, and various improvements. Both the 727-venture and Brushfam iterations of this library seem to be in a state of disrepair, which prompted us to take it over. It's important to note that, at present, generating TypeScript code from a contract is functional, but only through the command line. The functionality of calling via JavaScript and the plugin system is currently flawed. We plan to address and rectify these issues in the near future.

### Installation & import

Install the package as dependency:

```bash
npm i @727-ventures/typechain-polkadot
npm i @prosopo/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`):
```bash
npx @727-ventures/typechain-polkadot --in artifacts --out typed_contracts
npx @prosopo/typechain-polkadot --in artifacts --out typed_contracts
```

Import the contract what you want to use(in the example it is [`my_psp22`](https://github.com/727-Ventures/openbrush-contracts/tree/main/examples/psp22)):
Expand Down Expand Up @@ -107,11 +77,3 @@ For example, you can generate code for different contracts with different logic,
- [Examples](examples/README.md)
- [Article 1](https://medium.com/p/7c184067523f)
- [Article 2](https://medium.com/brushfam/ways-how-to-use-typechain-polkadot-in-your-project-281ef80b8dd8)

## Roadmap 🚗

Typechain participates in the Web3 Grants, you can find the roadmap there:
- [Grant I](https://github.com/w3f/Grants-Program/blob/master/applications/typechain-polkadot-follow-up.md)
- [Delivery milestone 1](https://github.com/w3f/Grant-Milestone-Delivery/blob/master/deliveries/typechain-polkadot-milestone-1.md#milestone-delivery-mailbox)
- [Delivery milestone 2](https://github.com/w3f/Grant-Milestone-Delivery/blob/master/deliveries/typechain-polkadot-milestone-2.md)
- [Delivery milestone 3](https://github.com/w3f/Grant-Milestone-Delivery/blob/master/deliveries/typechain-polkadot-follow-up-2.md)
16 changes: 8 additions & 8 deletions docs/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ To dive deeper into configuration, you can check [typechain-compiler documentati
Add the following to your `package.json`:
```json
"dependencies": {
"@727-ventures/typechain-compiler": "^0.5.16",
"@727-ventures/typechain-types": "^0.0.22",
"@prosopo/typechain-compiler": "^0.5.16",
"@prosopo/typechain-types": "^0.0.22",
"@types/node": "^17.0.34",
"ts-node": "^10.7.0",
"typescript": "^4.6.4",
"@polkadot/api": "^10.8.1",
"@polkadot/api-contract": "^10.8.1",
"@polkadot/api": "10.9.1",
"@polkadot/api-contract": "10.9.1",
"@polkadot/keyring": "^10.4.2",
"@types/bn.js": "^5.1.0"
}
Expand All @@ -166,7 +166,7 @@ And install it with `npm install`.

7) Now, let's run `typechain-compiler`:
```bash
$ npx @727-ventures/typechain-compiler --config typechain.config.json
$ npx @prosopo/typechain-compiler --config typechain.config.json
```

8) And now, you can use generated code in your project. For example, you can create a file `index.ts`:
Expand Down Expand Up @@ -385,7 +385,7 @@ cargo contract build

2) And now, let's install `typechain-polkadot`:
```bash
$ npm install @727-ventures/typechain-polkadot
$ npm install @prosopo/typechain-polkadot
```

3) Let's create a directory with artifacts:
Expand All @@ -406,9 +406,9 @@ $ cp ./contracts/psp22/target/ink/metadata.json artifacts/psp22.json

5) Let's run `typechain-polkadot`:
```bash
$ npx @727-ventures/typechain-polkadot --in ./artifacts --out ./typechain-generated
$ npx @prosopo/typechain-polkadot --in ./artifacts --out ./typechain-generated
```

Wow! We've just generated code for our contracts using typechain directly! 🎉

> For more information about `typechain-polkadot` you can check [typechain-polkadot documentation](../packages/typechain-polkadot/README.md)
> For more information about `typechain-polkadot` you can check [typechain-polkadot documentation](../packages/typechain-polkadot/README.md)
12 changes: 6 additions & 6 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ This directory contains examples of parsed contracts and pieces of advice how to
- Add to your package.json file the following and install it with `npm i`:
```json
"dependencies": {
"@727-ventures/typechain-polkadot": "0.6.8",
"@727-ventures/typechain-types": "^0.0.22",
"@prosopo/typechain-polkadot": "0.6.8",
"@prosopo/typechain-types": "^0.0.22",
"@types/node": "^17.0.34",
"ts-node": "^10.7.0",
"typescript": "^4.6.4",
"@polkadot/api": "^10.8.1",
"@polkadot/api-contract": "^10.8.1",
"@polkadot/api": "10.9.1",
"@polkadot/api-contract": "10.9.1",
"@types/bn.js": "^5.1.0"
}
```
- Run typechain with
```bash
npx @727-ventures/typechain-polkadot --in path/to/artifacts --out path/to/output
npx @prosopo/typechain-polkadot --in path/to/artifacts --out path/to/output
```

> Note: you should move metadata.json to artifacts directory and rename it to <contract-name>.json, also if you want to deploy the contract you should also move <contract-name>.contract to artifacts directory from your target dir
> Note: you should move metadata.json to artifacts directory and rename it to <contract-name>.json, also if you want to deploy the contract you should also move <contract-name>.contract to artifacts directory from your target dir
4 changes: 2 additions & 2 deletions examples/plugins/output/build-extrinsic/my_psp22.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* This file is auto-generated */

import type { ContractPromise } from '@polkadot/api-contract';
import type { GasLimit, GasLimitAndRequiredValue } from '@727-ventures/typechain-types';
import { buildSubmittableExtrinsic } from '@727-ventures/typechain-types';
import type { GasLimit, GasLimitAndRequiredValue } from '@prosopo/typechain-types';
import { buildSubmittableExtrinsic } from '@prosopo/typechain-types';
import type * as ArgumentTypes from '../types-arguments/my_psp22';
import type BN from 'bn.js';
import type { ApiPromise } from '@polkadot/api';
Expand Down
5 changes: 3 additions & 2 deletions examples/plugins/output/constructors/my_psp22.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {CodePromise} from "@polkadot/api-contract";
import type {KeyringPair} from "@polkadot/keyring/types";
import Files from "fs";
import type {ApiPromise} from "@polkadot/api";
import {_genValidGasLimitAndValue, _signAndSend, SignAndSendSuccessResponse} from "@727-ventures/typechain-types";
import type {ConstructorOptions} from "@727-ventures/typechain-types";
import {_genValidGasLimitAndValue, _signAndSend, SignAndSendSuccessResponse} from "@prosopo/typechain-types";
import type {ConstructorOptions} from "@prosopo/typechain-types";
import type {WeightV2} from "@polkadot/types/interfaces";
import type * as ArgumentTypes from '../types-arguments/my_psp22';
import type BN from 'bn.js';
Expand Down Expand Up @@ -46,6 +46,7 @@ export default class Constructors {

return {
result: response as SignAndSendSuccessResponse,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
address: (response as SignAndSendSuccessResponse)!.result!.contract.address.toString(),
};
Expand Down
2 changes: 1 addition & 1 deletion examples/plugins/output/event-types/my_psp22.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type {ReturnNumber} from "@727-ventures/typechain-types";
import type {ReturnNumber} from "@prosopo/typechain-types";
import type * as ReturnTypes from '../types-returns/my_psp22';

3 changes: 2 additions & 1 deletion examples/plugins/output/events/my_psp22.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type * as EventTypes from '../event-types/my_psp22';
import type {ContractPromise} from "@polkadot/api-contract";
import type {ApiPromise} from "@polkadot/api";
import {getEventTypeDescription} from "../shared/utils";
import {handleEventReturn} from "@727-ventures/typechain-types";
import {handleEventReturn} from "@prosopo/typechain-types";

export default class EventsClass {
private __nativeContract : ContractPromise;
Expand All @@ -21,6 +21,7 @@ export default class EventsClass {
callback : (args: any[], event: any) => void,
filter : (eventName: string) => boolean = () => true
) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return this.__api.query.system.events((events) => {
events.forEach((record: any) => {
Expand Down
30 changes: 16 additions & 14 deletions examples/plugins/output/mixed-methods/my_psp22.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
import type { ContractPromise } from '@polkadot/api-contract';
import type { ApiPromise } from '@polkadot/api';
import type { KeyringPair } from '@polkadot/keyring/types';
import type { GasLimit, GasLimitAndRequiredValue, Result } from '@727-ventures/typechain-types';
import type { QueryReturnType } from '@727-ventures/typechain-types';
import { queryOkJSON, queryJSON, handleReturnType } from '@727-ventures/typechain-types';
import { txSignAndSend } from '@727-ventures/typechain-types';
import type { GasLimit, GasLimitAndRequiredValue, Result } from '@prosopo/typechain-types';
import type { QueryReturnType } from '@prosopo/typechain-types';
import { queryOkJSON, queryJSON, handleReturnType } from '@prosopo/typechain-types';
import { txSignAndSend } from '@prosopo/typechain-types';
import type * as ArgumentTypes from '../types-arguments/my_psp22';
import type * as ReturnTypes from '../types-returns/my_psp22';
import type BN from 'bn.js';
//@ts-ignore
import {ReturnNumber} from '@727-ventures/typechain-types';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import {ReturnNumber} from '@prosopo/typechain-types';
import {getTypeDescription} from './../shared/utils';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import type {EventRecord} from "@polkadot/api/submittable";
import type { EventRecord } from '@polkadot/types/interfaces';
import {decodeEvents} from "../shared/utils";


Expand Down Expand Up @@ -47,7 +49,7 @@ export default class Methods {
amount: (string | number | BN),
__options: GasLimit,
){
return txSignAndSend( this.__apiPromise, this.__nativeContract, this.__keyringPair, "mintTo", (events: EventRecord) => {
return txSignAndSend( this.__apiPromise, this.__nativeContract, this.__keyringPair, "mintTo", (events: EventRecord[]) => {
return decodeEvents(events, this.__nativeContract, "my_psp22");
}, [account, amount], __options);
}
Expand All @@ -68,7 +70,7 @@ export default class Methods {
data: Array<(number | string | BN)>,
__options: GasLimit,
){
return txSignAndSend( this.__apiPromise, this.__nativeContract, this.__keyringPair, "psp22::transferFrom", (events: EventRecord) => {
return txSignAndSend( this.__apiPromise, this.__nativeContract, this.__keyringPair, "psp22::transferFrom", (events: EventRecord[]) => {
return decodeEvents(events, this.__nativeContract, "my_psp22");
}, [from, to, value, data], __options);
}
Expand All @@ -85,7 +87,7 @@ export default class Methods {
deltaValue: (string | number | BN),
__options: GasLimit,
){
return txSignAndSend( this.__apiPromise, this.__nativeContract, this.__keyringPair, "psp22::decreaseAllowance", (events: EventRecord) => {
return txSignAndSend( this.__apiPromise, this.__nativeContract, this.__keyringPair, "psp22::decreaseAllowance", (events: EventRecord[]) => {
return decodeEvents(events, this.__nativeContract, "my_psp22");
}, [spender, deltaValue], __options);
}
Expand Down Expand Up @@ -126,7 +128,7 @@ export default class Methods {
value: (string | number | BN),
__options: GasLimit,
){
return txSignAndSend( this.__apiPromise, this.__nativeContract, this.__keyringPair, "psp22::approve", (events: EventRecord) => {
return txSignAndSend( this.__apiPromise, this.__nativeContract, this.__keyringPair, "psp22::approve", (events: EventRecord[]) => {
return decodeEvents(events, this.__nativeContract, "my_psp22");
}, [spender, value], __options);
}
Expand All @@ -143,7 +145,7 @@ export default class Methods {
deltaValue: (string | number | BN),
__options: GasLimit,
){
return txSignAndSend( this.__apiPromise, this.__nativeContract, this.__keyringPair, "psp22::increaseAllowance", (events: EventRecord) => {
return txSignAndSend( this.__apiPromise, this.__nativeContract, this.__keyringPair, "psp22::increaseAllowance", (events: EventRecord[]) => {
return decodeEvents(events, this.__nativeContract, "my_psp22");
}, [spender, deltaValue], __options);
}
Expand Down Expand Up @@ -177,7 +179,7 @@ export default class Methods {
data: Array<(number | string | BN)>,
__options: GasLimit,
){
return txSignAndSend( this.__apiPromise, this.__nativeContract, this.__keyringPair, "psp22::transfer", (events: EventRecord) => {
return txSignAndSend( this.__apiPromise, this.__nativeContract, this.__keyringPair, "psp22::transfer", (events: EventRecord[]) => {
return decodeEvents(events, this.__nativeContract, "my_psp22");
}, [to, value, data], __options);
}
Expand All @@ -194,7 +196,7 @@ export default class Methods {
amount: (string | number | BN),
__options: GasLimit,
){
return txSignAndSend( this.__apiPromise, this.__nativeContract, this.__keyringPair, "psp22Mintable::mint", (events: EventRecord) => {
return txSignAndSend( this.__apiPromise, this.__nativeContract, this.__keyringPair, "psp22Mintable::mint", (events: EventRecord[]) => {
return decodeEvents(events, this.__nativeContract, "my_psp22");
}, [account, amount], __options);
}
Expand Down
11 changes: 6 additions & 5 deletions examples/plugins/output/query/my_psp22.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import type { ContractPromise } from '@polkadot/api-contract';
import type { ApiPromise } from '@polkadot/api';
import type { GasLimit, GasLimitAndRequiredValue, Result } from '@727-ventures/typechain-types';
import type { QueryReturnType } from '@727-ventures/typechain-types';
import { queryJSON, queryOkJSON, handleReturnType } from '@727-ventures/typechain-types';
import type { GasLimit, GasLimitAndRequiredValue, Result } from '@prosopo/typechain-types';
import type { QueryReturnType } from '@prosopo/typechain-types';
import { queryJSON, queryOkJSON, handleReturnType } from '@prosopo/typechain-types';
import type * as ArgumentTypes from '../types-arguments/my_psp22';
import type * as ReturnTypes from '../types-returns/my_psp22';
import type BN from 'bn.js';
//@ts-ignore
import {ReturnNumber} from '@727-ventures/typechain-types';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import {ReturnNumber} from '@prosopo/typechain-types';
import {getTypeDescription} from './../shared/utils';


Expand Down
2 changes: 1 addition & 1 deletion examples/plugins/output/shared/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from "fs";
import type {ContractPromise} from "@polkadot/api-contract";
import {handleEventReturn} from "@727-ventures/typechain-types";
import {handleEventReturn} from "@prosopo/typechain-types";

export function getTypeDescription(id: number | string, fileName: string): any {
const types = JSON.parse(fs.readFileSync(__dirname + `/../data/${fileName}.json`, 'utf8'));
Expand Down
Loading
Loading