Skip to content

Tons of Typescript code examples, to use Starknet.js to interact with Starkware Starknet network (mainly on starknet-devnet-rs)

Notifications You must be signed in to change notification settings

meganodeorg/starknet.js-workshop-typescript

 
 

Repository files navigation

Starkware Starknet network ^0.12.3

Cairo Accounts and ERC20 Demo

Typescript code, using Starknet.js v5.24.3 and local Starknet-devnet-rs

Starknet.js

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.

🛠️ Installation 🛠️

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
  • Install Starknet-devnet-rs 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.12.2, Starknet-devnet-rs v0.1.0, starknet.js v5.21.1. Due to fast iterations of Starknet and Cairo, this script will probably be quickly out-of-date.

The Account contract used in this workshop is made by OpenZeppelin, contract version 0.7.0.

🚀 Start the demo 🚀 🎆 ↘️ 💩

Open a console, and launch the devnet cargo run --release -- --seed 0

Open a second console, and launch the script :
npx ts-node src/starknet_jsNewAccount.ts

When you see that you have to fund your new wallet, it's automatic in devnet.
Faucet for devnet, if necessary :

curl -X POST http://127.0.0.1:5050/mint -d '{"address":"0x1234","amount":50000000000000000000,"lite":true}' -H "Content-Type:application/json"

or source ./src/scripts/mintWallet.sh

More easy : use npx ts-node src/starknet_jsExistingAccount.ts, using preexisting account #0 created automatically during Devnet-rs launch.

📜 scripts :

In the folder 'scripts', you can find many pedagogical codes :

Accounts :

  • Create accounts
  • Connect account
    • Connect predeployed account (only on devnet) script1
    • Connect created account script8

Contracts :

Interactions

Others :

You can find in this repo tons of other scripts. Dig in and find many usefull exemples of code.
To simplify the test of these scripts, take advantage to install the extension code runner. In the code window, right click, then run code.

Cairo 1 :

You can find some explanations for the use of Starknet.js with Cairo v1&v2 smart-contracts here.

Demo DAPP - Cairo1-JS :

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

Proxy :

Some explanations to interact with a contract behind a proxy here

🤔 Questions?

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

🙏 Inspiration :

This script is a fork of https://github.com/0xs34n/starknet.js-workshop

About

Tons of Typescript code examples, to use Starknet.js to interact with Starkware Starknet network (mainly on starknet-devnet-rs)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 71.4%
  • Cairo 24.4%
  • Python 4.0%
  • Other 0.2%