Skip to content

Simple exemple of use of starknet.js (starkware Starknet network, code in Cairo) with typescript and starknet-devnet

Notifications You must be signed in to change notification settings

zizou0x/starknet.js-workshop-typescript

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Starkware Starknet network ^0.10.3

Cairo Accounts and ERC20 Demo

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

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 (very) slow. To speed up the execution, we use Starknet-devnet, 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 Python 3.9 here
  • Create a Starknet environment here, with cairo 0.10.3 minimum.
  • Install Starknet-devnet here

Run npm install in this directory.

The file .env defines the network to use. It's currently configured for the local devnet. As explained in the file, you can change easily to Testnet (1 or 2) or Mainnet.

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.10.3, starknet-devnet v0.4.6, starknet.js v5.1.0. 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.6.1.

🚀 Start the demo 🚀 🎆 ↘️ 💩

Open a console, and launch the devnet starknet-devnet --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 ./mintWallet.sh

More easy : use npx ts-node src/starknet_jsExistingAccount.ts, using preexisting account #0 created automatically during Devnet 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 :

  • Declare contract script9
  • Deploy contract
    • Deploy with OZ deployer 0.5.0 (UDC) script4
  • Declare & deploy contract with OZ deployer 0.5.0 (UDC) script5

Interactions

Cairo 1:

You can find some explanations for the use of Starknet.js with Cairo 1 smart-contracts 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

Simple exemple of use of starknet.js (starkware Starknet network, code in Cairo) with typescript and starknet-devnet

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Cairo 54.0%
  • TypeScript 34.2%
  • Python 11.5%
  • Other 0.3%