Skip to content

Commit

Permalink
feat: full support for cairo v2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
haroune-mohammedi committed Oct 20, 2023
1 parent b097041 commit b8510c3
Show file tree
Hide file tree
Showing 7 changed files with 357 additions and 2,157 deletions.
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,26 @@ abiwan will support multiple Cairo compiler versions, but not in parallel - diff

Currently supported:

| Abi-Wan npm | Cairo compiler |
| ------------- | ------------- |
| [1.0.3](https://www.npmjs.com/package/abi-wan-kanabi/v/1.0.3) | [Cairo v1.0.0](https://github.com/starkware-libs/cairo/releases/tag/v1.0.0) <br> [Cairo v1.1.0](https://github.com/starkware-libs/cairo/releases/tag/v1.1.0) |
| Abi-Wan npm | Cairo compiler |
| ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [1.0.3](https://www.npmjs.com/package/abi-wan-kanabi/v/1.0.3) | [Cairo v1.0.0](https://github.com/starkware-libs/cairo/releases/tag/v1.0.0) <br> [Cairo v1.1.0](https://github.com/starkware-libs/cairo/releases/tag/v1.1.0) |
| [2.0.0](https://www.npmjs.com/package/abi-wan-kanabi/v/2.0.0) | [Cairo v2.3.0-rc0](https://github.com/starkware-libs/cairo/releases/tag/v2.3.0-rc0) |

### Build

To use abiwan, you must first generate types from your contracts' ABI json files, for example using the helper script (deprecated):
To use abiwan, you must first generate types from your contracts' ABI json files, you can use the the helper script:

```bash
./scripts/extract_abi.sh <path>/<to>/<abi>.json <path>/<to>/<other_abi>.json ./
npm run generate -- --input /path/to/abi.json --output /path/to/abi.ts
```

This will create a declaration file (.d.ts) for the abi.
This will create a typescript file for the abi.
You can then import it in any script and you are set to go:

```typescript
import abi from "./abi_demo.ts";
import { call } from "./kannabi.ts";
call(abi, "balance_of", 5n);
import abi from "./path/to/abi";
import { call } from "./kanabi";
const balance = call(abi, "balance_of", 5n);
```

> If you think that we should be able to import types directly from the json files, we think so too!
Expand All @@ -78,14 +79,17 @@ call(abi, "balance_of", 5n);
npm run typecheck
```

### Generate `test/example.ts` from `test/example.json`
### Generate `test/example.ts`

```bash
npm run generate -- --input test/example.json --output test/example.ts
# First build the example project with `scarb`
cd test/example
scarb build
# Then generate test/example.ts
cd ../..
npm run generate -- --input test/example/target/dev/example_example_contract.contract_class.json --output test/example.ts
```

Note: `test/example.json` was generated by `starknet-compile test/example.cairo test/example.json`

### Demo

https://drive.google.com/file/d/1OpIgKlk-okvwJn-dkR2Pq2FvOVwlXTUJ/view?usp=sharing
Expand All @@ -96,7 +100,7 @@ Abiwan is still very young and has not yet been subject to an official release.

##  Supported Cairo Types

Abi-wan-kanabi supports all of Cairo 1 types, here's the mapping between Cairo types and Typescript types
Abi-wan-kanabi supports all of Cairo types, here's the mapping between Cairo types and Typescript types

### Primitive Types

Expand All @@ -106,6 +110,7 @@ Abi-wan-kanabi supports all of Cairo 1 types, here's the mapping between Cairo t
| `u8 - u32` | `number \| bigint`  |
| `u64 - u256` | `number \| bigint \| Uint256`  |
| `ContractAddress`  | `string` |
| `ClassHash`  | `string` |
| `bool` | `boolean`  |
| `()`  | `void` |

Expand Down
89 changes: 0 additions & 89 deletions test/example.cairo

This file was deleted.

Loading

0 comments on commit b8510c3

Please sign in to comment.