Skip to content

Latest commit

 

History

History
62 lines (50 loc) · 1.84 KB

step-04.md

File metadata and controls

62 lines (50 loc) · 1.84 KB

Using low level starknet.dart API

In this step, you will adapt flutter demo counter to use your smart contract.

To ease usage of devnet, starknet.dart provide the account0 object which represent the first predeployed account of devnet.

Create application directory

Create a new flutter application

flutter create app

pubspec overrides

Create a file named pubspec_overrides.yaml in your app directory with the following content:

dependency_overrides:
  starknet:
      git:
        url: https://github.com/focustree/starknet.dart
        path: packages/starknet
  starknet_builder:
      git:
        url: https://github.com/focustree/starknet.dart
        path: packages/starknet_builder

Since starknet.dart is not yet released, you will use the latest version on github.

Update pubspec

Add starknet in dependencies, starknet_builder and build_runner in build_dependcies in your app/pubspec.yaml

And then run

flutter pub get

Running your app

With flutter, you can't specify any arguments to main, so you need to use environment

flutter run -d linux --dart-define-from-file=../contracts/deployment.json 

To retrieve contract address value in your code:

const contractAddress = String.fromEnvironment("address");

Generate source code from sierra JSON file

To generate source code from a sierra JSON file, the first step is to extract the ABI from this file.

mkdir app/lib/src
dart run ./tool/bin/extract_sierra_json.dart --input ./contracts/target/dev/contracts_Counter.sierra.json --output ./app/lib/src/counter.sierra.json

You can now execute build_runner to generate a file named counter.sierra.g.dart

cd app
dart run build_runner build