Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions www/docs/guides/L1message.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ sidebar_position: 14

You can exchange messages between L1 & L2 networks:

- L2 Starknet mainnet ↔️ L1 Ethereum.
- L2 Starknet testnet ↔️ L1 Sepolia ETH testnet.
- L2 local Starknet devnet ↔️ L1 local ETH testnet (anvil, ...).
- L2 Starknet Mainnet ↔️ L1 Ethereum.
- L2 Starknet Testnet ↔️ L1 Sepolia ETH testnet.
- L2 local Starknet Devnet ↔️ L1 local ETH testnet (anvil, ...).

You can find an explanation of the global mechanism [here](https://docs.starknet.io/documentation/architecture_and_concepts/L1-L2_Communication/messaging-mechanism/).
You can find an explanation of the global mechanism [here](https://docs.starknet.io/architecture-and-concepts/network-architecture/messaging-mechanism/).

Most of the code for this messaging process will be written in Cairo, but Starknet.js provides some functionalities for this subject.

Expand Down
2 changes: 1 addition & 1 deletion www/docs/guides/cairo_enum.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ const res14e = (await myTestContract.call('test2a', [
])) as bigint;
```

Take care that if you call a method that do not use the abi (as `CallData.compile`), you have to list all the variants of the enum, like this:
Take care that if you call a method that do not use the ABI (as `CallData.compile`), you have to list all the variants of the enum, like this:

```typescript
const orderToSend: Order = { p1: 8, p2: 10 };
Expand Down
36 changes: 23 additions & 13 deletions www/docs/guides/connect_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ You need 2 pieces of data:
import { Account, RpcProvider } from 'starknet';
```

## Connect to a pre-deployed account in Starknet-devnet-rs
## Connect to a pre-deployed account in Starknet Devnet

When you launch starknet-devnet-rs, 10 accounts are pre-deployed with 100 dummy ETH in each.
When you launch `starknet-devnet`, 10 accounts are pre-deployed with 100 dummy ETH and STRK in each.

Addresses and private keys are displayed on the console at initialization.

Expand All @@ -34,23 +34,17 @@ Public key : 0x7e52885445756b313ea16849145363ccb73fb4ab0440dbac333cf9d13de82b9
Then you can use this code:

```typescript
// initialize provider
// initialize provider for Devnet v0.3.0
const provider = new RpcProvider({ nodeUrl: 'http://127.0.0.1:5050/rpc' });
// initialize existing pre-deployed account 0 of Devnet
const privateKey = '0x71d7bb07b9a64f6f78ac4c816aff4da9';
// initialize existing account 0 pre-deployed on Devnet
const accountAddress = '0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691';
const privateKey = '0x71d7bb07b9a64f6f78ac4c816aff4da9';

const account = new Account(provider, accountAddress, privateKey);
```

Your account is now connected, and you can use it.

```typescript
const account = new Account(provider, accountAddress, privateKey);
```

> Take care that this added parameter is a string, NOT a number.

## 👛 Connect to an existing account (in any network)

The code is the same, you just have to:
Expand All @@ -65,7 +59,7 @@ For example, to connect an existing account on testnet, with a private key store
import * as dotenv from 'dotenv';
dotenv.config();

// initialize provider
// initialize RPC v0.8 provider
const provider = new RpcProvider({ nodeUrl: `${myNodeUrl}` });
// initialize existing account
const privateKey = process.env.OZ_NEW_ACCOUNT_PRIVKEY;
Expand All @@ -74,9 +68,25 @@ const accountAddress = '0x051158d244c7636dde39ec822873b29e6c9a758c6a9812d005b628
const account = new Account(provider, accountAddress, privateKey);
```

:::tip
If you are connected to an RPC v0.7 node and you want to use ETH as fees for this account:

```typescript
const myAccount = new Account(
provider,
accountAddress,
privateKey,
undefined,
ETransactionVersion.V2
);
```

:::

## Connect to an account that uses Ethereum signature

As a consequence of account abstraction, you can find accounts that uses Ethereum signature logical.
Accounts that use Ethereum signatures are possible because of account abstraction.

To connect to this type of account:

```typescript
Expand Down
6 changes: 3 additions & 3 deletions www/docs/guides/connect_contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Once your provider is initialized, you can connect a contract already deployed i
You need 2 pieces of data:

- the address of the contract
- the ABI file of the contract (or the compiled/compressed contract file, that includes the abi)
- the ABI file of the contract (or the compiled/compressed contract file, that includes the ABI)

> If you don't have the abi file, the `provider.getClassAt()` and `provider.getClassByHash()` commands will recover the compressed contract file. As these methods generate a significant workload for the sequencer/node, it's recommended to store the result on your computer to be able to reuse it later without using the provider each time:
> If you don't have the ABI file, the `provider.getClassAt()` and `provider.getClassByHash()` commands will recover the compressed contract file. As these methods generate a significant workload for the node, it's recommended to store the result on your computer to be able to reuse it later without using the provider each time:

```typescript
import fs from 'fs';
Expand All @@ -22,7 +22,7 @@ fs.writeFileSync('./myAbi.json', json.stringify(compressedContract.abi, undefine

> When possible, prefer to read the compiled contract from a local Json file, as it's much more faster, using the `json.parse` util provided by Starknet.js, as shown below.

## Get the abi from a compiled/compressed file
## Get the ABI from a compiled/compressed file

```typescript
import { RpcProvider, Contract, json } from 'starknet';
Expand Down
156 changes: 110 additions & 46 deletions www/docs/guides/connect_network.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 3

# RpcProvider object 🔌 connect to the network

The first thing to do is to define with which network you want to interact.
The first thing to do is to define with which network you want to interact (Mainnet, Testnet, Devnet, ...).

Then you need to select a node. A node is a safe way to connect with the Starknet blockchain. You can use:

Expand All @@ -13,47 +13,85 @@ Then you need to select a node. A node is a safe way to connect with the Starkne
- your own node, located on your local computer or in your local network.
> you can spin up your own node with Pathfinder, Juno, Papyrus, Deoxys, ...
- a local development node, that simulates a Starknet network. Useful for devs to perform quick tests without spending precious fee token.
> Main development devnets are Starknet-devnet-rs, Madara, ...
> Main development devnets are Starknet Devnet, Madara, ...

Each node is communicating with Starknet.js using a rpc specification. Most of the nodes are able to use 2 rpc spec versions.
For example, this node is compatible with v0.6.0 & v0.7.0, using the following entry points :
Starknet.js communicates with nodes in accordance to a version of the RPC specification. Most nodes are able to use two RPC versions.
For example, this node is compatible with v0.7.1 and v0.8.0, using the following entry points:

- "https://free-rpc.nethermind.io/sepolia-juno/v0_6"
- "https://free-rpc.nethermind.io/sepolia-juno/v0_7"
- "https://free-rpc.nethermind.io/sepolia-juno/v0_8"

From rpc spec v0.5.0, you can request the rpc spec version that uses a node address :
From RPC v0.5.0, you can make a request to retrieve the RPC version that a node uses:

```typescript
const resp = await myProvider.getSpecVersion();
console.log('rpc version =', resp);
// result : rpc version = 0.7.0
console.log('RPC version =', resp);
// result: RPC version = 0.8.0
```

On Starknet.js side, you have to select the proper version, to be in accordance with the node you want to use :
The Starknet.js version must align with the RPC version supported by the chosen node as shown below:

| Rpc spec version of your node | Starknet.js version to use |
| :---------------------------: | ---------------------------- |
| v0.4.0 | Starknet.js v5.21.1 |
| v0.5.0 | Starknet.js v5.23.0 |
| v0.5.1 | Starknet.js v5.29.0 & v6.1.0 |
| v0.6.0 | Starknet.js v6.23.1 |
| v0.7.1 | Starknet.js v6.23.1 |
| RPC spec version of your node | Starknet.js version to use |
| :---------------------------: | ----------------------------- |
| v0.4.0 | Starknet.js v5.21.1 |
| v0.5.0 | Starknet.js v5.23.0 |
| v0.5.1 | Starknet.js v5.29.0 or v6.1.0 |
| v0.6.0 | Starknet.js v6.24.1 |
| v0.7.1 | Starknet.js v6.24.1 or v7.0.1 |
| v0.8.0 | Starknet.js v7.0.1 |

:::note
Each Starknet.js version 6.x.x is compatible with 2 rpc spec versions, and recognize automatically the spec version if not provided.
From version 6.x.x, Starknet.js is compatible with two RPC spec versions.
:::

With the `RpcProvider` class, you define the Starknet Rpc node to use.
With the `RpcProvider` class, you define the Starknet RPC node to use:

```typescript
import { RpcProvider } from 'starknet';
```

## Connect your DAPP to an RPC node provider

### Default Rpc node
### Available nodes

If you don't want to use a specific node, or to handle an API key, you can use by default (using Rpc spec 0.7.0):
**Mainnet network:**

| Node | with public url | with API key |
| -----------------------: | :--------------: | :--------------: |
| Alchemy | No | v0_6, v0_7 |
| Infura | No | v0_7 |
| Blast | v0_6, v0_7, v0_8 | v0_6, v0_7, v0_8 |
| Nethermind | v0_6, v0_7, v0_8 | No |
| Lava | v0_6, v0_7, v0_8 | v0_8 |
| Local Pathfinder v0.16.2 | v0_6, v0_7, v0_8 | N/A |
| Local Juno v0.14.2 | v0_6, v0_7, v0_8 | N/A |

**Sepolia Testnet network:**

| Node | with public url | with API key |
| -----------------------: | :--------------: | :----------: |
| Alchemy | No | v0_6, v0_7 |
| Infura | No | v0_7 |
| Blast | v0_6, v0_7, v0_8 | No |
| Nethermind | v0_6, v0_7, v0_8 | No |
| Lava | v0_6, v0_7, v0_8 | No |
| Local Pathfinder v0.16.2 | v0_6, v0_7, v0_8 | N/A |
| Local Juno v0.14.2 | v0_6, v0_7, v0_8 | N/A |

**Local Starknet Devnet network:**

| Node | with public url | with API key |
| ---------------------: | :-------------: | :----------: |
| starknet-devnet v0.2.4 | v0_7 | N/A |
| starknet-devnet v0.3.0 | v0_8 | N/A |

:::note
This status has been verified 02/apr/2025.
:::

### Default RPC node

If you don't want to use a specific node or to handle an API key, you can use one of the defaults (using RPC spec v0.8.0):

```typescript
const myProvider = new RpcProvider({ nodeUrl: constants.NetworkName.SN_SEPOLIA });
Expand All @@ -62,67 +100,93 @@ const myProvider = new RpcProvider({ nodeUrl: constants.NetworkName.SN_MAIN });
const myProvider = new RpcProvider(); // Sepolia
```

> when using this syntax, a random public node will be selected.
> When using this syntax, a random public node will be selected.

Using a specific nodeUrl is the better approach, as such a node will have fewer limitations, the last version of software and will be less crowded.
Using a specific `nodeUrl` is the better approach, as such nodes will have fewer limitations, their software will be more up to date, and they will be less congested.

Some examples of RpcProvider instantiation to connect to RPC node providers:
Some examples of `RpcProvider` instantiation to connect to RPC node providers:

### Mainnet

```typescript
// Infura node rpc 0.5.1 for Mainnet:
// Infura node RPC 0.7.0 for Mainnet:
const providerInfuraMainnet = new RpcProvider({
nodeUrl: 'https://starknet-mainnet.infura.io/v3/' + infuraKey,
specVersion: '0.7',
});
// Blast node rpc 0.7.0 for Mainnet (0.4, 0.5 & 0_6 also available):
// Blast node RPC 0.8.0 for Mainnet (0.6 & 0_7 also available):
const providerBlastMainnet = new RpcProvider({
nodeUrl: 'https://starknet-mainnet.blastapi.io/' + blastKey + '/rpc/v0_7',
nodeUrl: 'https://starknet-mainnet.blastapi.io/' + blastKey + '/rpc/v0_8',
});
// Lava node rpc 0.6.0 for Mainnet:
// Lava node RPC 0.8.0 for Mainnet:
const providerMainnetLava = new RpcProvider({
nodeUrl: 'https://g.w.lavanet.xyz:443/gateway/strk/rpc-http/' + lavaMainnetKey,
});
// Alchemy node rpc 0.6.0 for Mainnet:
// Alchemy node RPC 0.7.0 for Mainnet (0_6 also available):
const providerAlchemyMainnet = new RpcProvider({
nodeUrl: 'https://starknet-mainnet.g.alchemy.com/starknet/version/rpc/v0_6/' + alchemyKey,
nodeUrl: 'https://starknet-mainnet.g.alchemy.com/starknet/version/rpc/v0_7/' + alchemyKey,
specVersion: '0.7',
});
// Public Nethermind node rpc 0.7.0 for Mainnet (0_6 also available):
// Public Nethermind node RPC 0.8.0 for Mainnet (0_6 & 0_7 also available):
const providerMainnetNethermindPublic = new RpcProvider({
nodeUrl: 'https://free-rpc.nethermind.io/mainnet-juno/v0_7',
nodeUrl: 'https://free-rpc.nethermind.io/mainnet-juno/v0_8',
});
// Public Blast node rpc 0.7.0 for Mainnet (0.4, 0.5 & 0_6 also available) :
// Public Blast node RPC 0.8.0 for Mainnet (0.6 & 0_7 also available):
const providerBlastMainnet = new RpcProvider({
nodeUrl: 'https://starknet-mainnet.public.blastapi.io/rpc/v0_7',
nodeUrl: 'https://starknet-mainnet.public.blastapi.io/rpc/v0_8',
});
// Public Lava node rpc 0.6.0 for Mainnet:
// Public Lava node RPC 0.8.0 for Mainnet (0.6 & 0_7 also available):
const providerLavaMainnet = new RpcProvider({
nodeUrl: 'https://json-rpc.starknet-mainnet.public.lavanet.xyz',
nodeUrl: 'https://rpc.starknet.lava.build/rpc/v0_8',
});
```

> Take care to safely manage your API key. It's a confidential item!

:::tip
If the RPC version of the node is 0.7, the `specVersion` parameter must be set:

```typescript
const myProvider = new RpcProvider({
nodeUrl: `${myNodeUrl}`,
specVersion: '0.7',
});
```

If you are not sure about the RPC version (0.7 or 0.8), use:

```typescript
const myProvider = await RpcProvider.create({ nodeUrl: `${myNodeUrl}` });
```

Note that this approach is slower, it performs a request to the node.
:::

### Goerli Testnet

:::info
The Goerli testnet is no more in service.
The Goerli Testnet is no longer in service.
:::

### Sepolia Testnet

```typescript
// Infura node rpc 0.5.1 for Sepolia Testnet :
// Infura node RPC 0.7.0 for Sepolia Testnet :
const providerInfuraSepoliaTestnet = new RpcProvider({
nodeUrl: 'https://starknet-sepolia.infura.io/v3/' + infuraKey,
specVersion: '0.7',
});
// Public Nethermind node rpc 0.7.0 for Sepolia Testnet (0_6 also available) :
// Public Nethermind node RPC 0.8.0 for Sepolia Testnet (0_6 & 0_7 also available) :
const providerSepoliaTestnetNethermindPublic = new RpcProvider({
nodeUrl: 'https://free-rpc.nethermind.io/sepolia-juno/v0_7',
nodeUrl: 'https://free-rpc.nethermind.io/sepolia-juno/v0_8',
});
// Public Blast node RPC 0.8.0 for Sepolia Testnet (0_6 & 0_7 also available) :
const providerSepoliaTestnetBlastPublic = new RpcProvider({
nodeUrl: 'https://starknet-sepolia.public.blastapi.io/rpc/v0_8',
});
// Public Blast node rpc 0.7.0 for Sepolia Testnet (0_6 also available) :
// Public Lava node RPC 0.8.0 for Sepolia Testnet (0_6 & 0_7 also available) :
const providerSepoliaTestnetBlastPublic = new RpcProvider({
nodeUrl: 'https://starknet-sepolia.public.blastapi.io/rpc/v0_7',
nodeUrl: 'https://rpc.starknet-testnet.lava.build/rpc/v0_8',
});
```

Expand All @@ -133,35 +197,35 @@ const providerSepoliaTestnetBlastPublic = new RpcProvider({
For a local [Pathfinder](https://github.com/eqlabs/pathfinder) node:

```typescript
const provider = new RpcProvider({ nodeUrl: '127.0.0.1:9545/rpc/v0_7' });
const provider = new RpcProvider({ nodeUrl: '127.0.0.1:9545/rpc/v0_8' });
```

Your node can be located in your local network (example: Pathfinder node running on a computer in your network, launched with this additional option: `--http-rpc 0.0.0.0:9545`).
You can connect with:

```typescript
const provider = new RpcProvider({ nodeUrl: '192.168.1.99:9545/rpc/v0_7' });
const provider = new RpcProvider({ nodeUrl: '192.168.1.99:9545/rpc/v0_8' });
```

### Juno

For a local [Juno](https://github.com/NethermindEth/juno) node initialize the provider with:

```typescript
const provider = new RpcProvider({ nodeUrl: 'http://127.0.0.1:6060/v0_7' });
const provider = new RpcProvider({ nodeUrl: 'http://127.0.0.1:6060/v0_8' });
```

> If Juno is running on a separate computer in your local network, don't forget to add the option `--http-host 0.0.0.0` when launching Juno.

## Devnet

Example of a connection to a local development node (rpc 0.7.0), with Starknet-devnet-rs v0.0.6:
Example of a connection to a local development node (RPC 0.8.0), with starknet-devnet v0.3.0:

```typescript
const provider = new RpcProvider({ nodeUrl: 'http://127.0.0.1:5050/rpc' });
```

> If you have customized host and port during starknet-devnet initialization, adapt in accordance your script.
> If you customized the host or port during starknet-devnet initialization, adapt the script accordingly.

## Batch JSON-RPC

Expand Down
Loading