Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: added waitForTransaction section and cleanups #675

Merged
merged 2 commits into from
Jul 5, 2023
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
17 changes: 9 additions & 8 deletions www/docs/guides/L1message.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ sidebar_position: 13

# Messages with L1 network

You can exchange messages between L1 & L2 networks :
You can exchange messages between L1 & L2 networks:

- L2 Starknet mainnet ↔️ L1 Ethereum.
- L2 Starknet testnet 1 & 2 ↔️ L1 Goerli ETH testnet.
- L2 local Starknet devnet ↔️ L1 local ETH testnet (Ganache, ...).

You can find 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/documentation/architecture_and_concepts/L1-L2_Communication/messaging-mechanism/).

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

## L1 ➡️ L2 messages

To send a message from L1 to L2, you need a solidity smart contract in the L1 network, calling the `SendMessageToL2` function of the Starknet core contract. The interface of this function :
To send a message from L1 to L2, you need a solidity smart contract in the L1 network, calling the `SendMessageToL2` function of the Starknet core contract.
The interface of this function:

```solidity
/**
Expand All @@ -31,7 +32,7 @@ function sendMessageToL2(
) external payable returns (bytes32, uint256);
```

You have to pay in the L1 an extra fee when invoking `sendMessageToL2` (of course paid with the L1 fee TOKEN), to pay the L2 part of the messaging mechanism. You can estimate this fee with this function :
You have to pay in the L1 an extra fee when invoking `sendMessageToL2` (of course paid with the L1 fee TOKEN), to pay the L2 part of the messaging mechanism. You can estimate this fee with this function:

```typescript
import { SequencerProvider } from "starknet";
Expand All @@ -45,13 +46,13 @@ const responseEstimateMessageFee = await provider.estimateMessageFee({
})
```

If the fee is paid in L1, the cairo contract at `to_Address` is automatically executed, function `entry_point_selector` (the function shall have a decorator `@l1_handler` in the Cairo code), with parameters `payload`.
If the fee is paid in L1, the Cairo contract at `to_Address` is automatically executed, function `entry_point_selector` (the function shall have a decorator `@l1_handler` in the Cairo code), with parameters `payload`.

## L2 ➡️ L1 messages

To send a message to L1, you will just invoke a cairo contract function, paying a fee that will pay all the process (in L1 & L2).
To send a message to L1, you will just invoke a Cairo contract function, paying a fee that will pay all the processes (in L1 & L2).

If necessary you can estimate this fee with the generic `estimateInvokeFee` function :
If necessary you can estimate this fee with the generic `estimateInvokeFee` function:

```typescript
const { suggestedMaxFee: estimatedFee1 } = await account0.estimateInvokeFee({
Expand Down
22 changes: 11 additions & 11 deletions www/docs/guides/connect_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
sidebar_position: 4
---

# 🔌 Connect an existing account
# 🔌 Connect to an existing account

Once your provider is initialized, you can connect an existing account.

You need 2 data :
You need 2 pieces of data:

- the address of the account
- the private key of this account
Expand All @@ -15,23 +15,23 @@ You need 2 data :
import { Account, Provider } from "starknet";
```

## Connect a predeployed account in Starknet-devnet
## Connect to a pre-deployed account in Starknet-devnet

When you launch starknet-devnet, 10 accounts are predeployed with 100 dummy ETH in each.
When you launch starknet-devnet, 10 accounts are pre-deployed with 100 dummy ETH in each.

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

> This data will change at each launch, so to freeze them, launch with : `starknet-devnet --seed 0`.
> This data will change at each launch, so to freeze them, launch with: `starknet-devnet --seed 0`.

The result for `account #0` :
The result for `account #0`:

```bash
Address: 0x7e00d496e324876bbc8531f2d9a82bf154d1a04a50218ee74cdd372f75a551a
Public key: 0x7e52885445756b313ea16849145363ccb73fb4ab0440dbac333cf9d13de82b9
Private key: 0xe3e70682c2094cac629f6fbed82c07cd
```

Then you can use this code :
Then you can use this code:

```typescript
// initialize provider
Expand All @@ -45,15 +45,15 @@ const account = new Account(provider, accountAddress, privateKey);

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

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

The code is exactly the same, you just have to :
The code is the same, you just have to:

- connect to the appropriate network.
- use the address of this account (public data).
- use the private key of this account (very sensitive data : your code MUST not disclose it).
- use the private key of this account (very sensitive data: your code MUST not disclose it).

For example, to connect an existing account to testnet, with a private key stored in .env non archived file :
For example, to connect an existing account on testnet, with a private key stored in a .env non-archived file:

```typescript
import * as dotenv from "dotenv";
Expand Down
8 changes: 4 additions & 4 deletions www/docs/guides/connect_contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ sidebar_position: 5

Once your provider is initialized, you can connect a contract already deployed in the network.

You need 2 data :
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)

> 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 to the sequencer/node, it's recommended to store the result in your computer, to be able to reuse it later without using the provider :
> 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 to the sequencer/node, it's recommended to store the result in your computer, to be able to reuse it later without using the provider:

```typescript
import fs from "fs";
Expand All @@ -27,15 +27,15 @@ fs.writeFileSync('./myAbi.json', json.stringify( compressedContract.abi, undefin
import { Provider, Contract, json } from "starknet";
```

If you have the compiled/compressed file of the contract, use this code to recover all data, including ABI :
If you have the compiled/compressed file of the contract, use this code to recover all data, including the ABI:

```typescript
const compiledContract = json.parse(fs.readFileSync("./compiledContracts/test.json").toString("ascii"));
```

> Note the `json.parse` util provided by Starknet.js

## Connect the contract
## Connect to the contract

```typescript
// initialize provider
Expand Down
15 changes: 8 additions & 7 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

# Provider object 🔌 connect to the network

First thing to do - define with which network you want to interact.
The first thing to do is to define with which network you want to interact.

With the Provider object, you define which network to use.

Expand Down Expand Up @@ -35,7 +35,7 @@ const provider = new Provider({ sequencer: { baseUrl:"http://127.0.0.1:5050"} })

## Connect your DAPP to a private Starknet network

If necessary you can have a full control on the network access (for example, for your company private test network) :
If necessary you can have full control of the network access (for example, for your company's private test network):

```typescript
const provider = new Provider({
Expand All @@ -49,13 +49,14 @@ const provider = new Provider({

## Connect your DAPP to a Starknet node

For a local [Pathfinder](https://github.com/eqlabs/pathfinder) node :
For a local [Pathfinder](https://github.com/eqlabs/pathfinder) node:

```typescript
const provider = new Provider({ rpc: { nodeUrl: '127.0.0.1:9545' } })
```

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

```typescript
const provider = new Provider({ rpc: { nodeUrl: '192.168.1.99:9545' } })
Expand All @@ -67,7 +68,7 @@ Some methods are available only if connected to a sequencer, and some others are

### Specific sequencer methods

For example, if you want to estimate the fee of a L1 ➡️ L2 message, you need to use a method that is available only in the sequencer. The class `SequencerProvider` is available for this case :
For example, if you want to estimate the fee of an L1 ➡️ L2 message, you need to use a method that is available only in the sequencer. The class `SequencerProvider` is available for this case:

```typescript
import { SequencerProvider, constants } from "starknet";
Expand All @@ -77,7 +78,7 @@ const responseEstimateMessageFee = await provider.estimateMessageFee(.....)

### Specific RPC methods

For example, if you want to read the events recorded in a range of blocks, you need to use a method available from a RPC node. The class `RpcProvider` is available for this case :
For example, if you want to read the events recorded in a range of blocks, you need to use a method available from an RPC node. The class `RpcProvider` is available for this case:

```typescript
import { RpcProvider } from "starknet";
Expand All @@ -93,7 +94,7 @@ let eventsList = await providerRPC.getEvents({

RPC providers are for example Infura, Alchemy, Chainstack... Or you can spin up your own Pathfinder node!

For example, to connect to Alchemy with your personal API key :
For example, to connect to Alchemy with your personal API key:

```typescript
const providerRPC = new RpcProvider({ nodeUrl: 'https://starknet-mainnet.g.alchemy.com/v2/' + alchemyKey});
Expand Down
Loading