If you want to implement the Starknet network in your DAPP, you can use starknet.js to interact with it.
These little scripts shows how to use and test very quickly your starknet.js code without any user interface.
Even if these codes are very small, it's a good guideline to always write them in Typescript.
Starknet mainnet and testnet are slow. To speed up the execution, we use Starknet-devnet-rs, that creates a local Starknet network.
copy this repo to your local disk.
Use cd starknet.js-workshop-typescript
to go to the root of the project.
If necessary :
- Install latest LTS version of node here
Run npm install
in this directory.
This repo is configured to be able to perform debugging of your typescript code. Just CTRL+SHIFT+D, then click on the green arrow.
This script has been written with cairo v0.13.3, Starknet-devnet-rs v0.2.3, starknet.js v6.20.3. Due to fast iterations of Starknet and Cairo, these scripts will probably be quickly out-of-date.
The Account contract used in this workshop is made by OpenZeppelin, contract version 0.9.0.
Open a console, and launch the script :
npx ts-node src/starknet_jsNewAccount.ts
devnet-rs is automatically launched and closed in this script.
More easy : use npx ts-node src/starknet_jsExistingAccount.ts
, using a preexisting account #0 created automatically at Devnet-rs launch.
In the folder 'scripts', you can find many pedagogical codes :
- Create accounts
- Connect account
- Connect a contract script7
- Call
- Invoke
Devnet-rs is launched and ended automatically in the main scripts of this tuto, using the starknet-devnet
library : https://github.com/0xSpaceShard/starknet-devnet-js/blob/master/README.md
If you prefer to have a devnet-rs already launched in its own console :
- To install and launch an instance of the local devnet-rs : https://github.com/0xSpaceShard/starknet-devnet-rs
- Open a console, and launch devnet-rs
cargo run --release -- --seed 0
- In all scripts, replace opening of a new Devnet by :
const myProvider = new RpcProvider({ nodeUrl: "http://127.0.0.1:5050/rpc" });
and remove kill
commands.
Most of the scripts in the subdirectories are using an already running devnet-rs.
You can find in this repo tons of other scripts. Dig in and find many useful examples of code (exotic signatures, Ledger Nano, L1L2 messaging, events handling, STRK fees, WebSocket, ...).
To simplify the test of these scripts, take advantage to install the extension code runner
. In the code window, right click, then run code
.
Be able to create some scripts is a good first step. The next step is the creation of DAPPs (decentralized application) ; see my demo DAPP for Starknet.
I made also an Airdrop DAPP demo.
Explore the code to see how to communicate with the wallet extensions of your browser.
Have a look in the starknet.js documentation.
Ask in #starknet-js channel in the Starknet Discord
Philippe. ROSTAN @ critical.devs.fr - Phil26#1686 on Discord
This script is a fork of https://github.com/0xs34n/starknet.js-workshop