Skip to content

Commit 7e0cffa

Browse files
PhilippeR26ivpavicipenovicp
authored
docs: use only RpcProvider
--------- Co-authored-by: Ivan Pavičić <ivan.pavicic@live.com> Co-authored-by: Petar Penović <penovicp@gmail.com>
1 parent 1fe93ed commit 7e0cffa

File tree

13 files changed

+103
-151
lines changed

13 files changed

+103
-151
lines changed

www/docs/guides/compiled_contracts/deployBraavos.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {
1111
DeployContractResponse,
1212
EstimateFeeDetails,
1313
InvocationsSignerDetails,
14-
Provider,
1514
RawCalldata,
15+
RpcProvider,
1616
constants,
1717
ec,
1818
hash,
@@ -116,7 +116,7 @@ async function buildBraavosAccountDeployPayload(
116116

117117
export async function estimateBraavosAccountDeployFee(
118118
privateKeyBraavos: BigNumberish,
119-
provider: Provider,
119+
provider: RpcProvider,
120120
{ blockIdentifier, skipValidate }: EstimateFeeDetails = {}
121121
): Promise<bigint> {
122122
const version = hash.feeTransactionVersion;
@@ -159,7 +159,7 @@ export async function estimateBraavosAccountDeployFee(
159159

160160
export async function deployBraavosAccount(
161161
privateKeyBraavos: BigNumberish,
162-
provider: Provider,
162+
provider: RpcProvider,
163163
max_fee?: BigNumberish
164164
): Promise<DeployContractResponse> {
165165
const nonce = constants.ZERO;

www/docs/guides/connect_account.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,33 @@ You need 2 pieces of data:
1212
- the private key of this account
1313

1414
```typescript
15-
import { Account, Provider } from "starknet";
15+
import { Account, RpcProvider } from "starknet";
1616
```
1717

18-
## Connect to a pre-deployed account in Starknet-devnet
18+
## Connect to a pre-deployed account in Starknet-devnet-rs
1919

20-
When you launch starknet-devnet, 10 accounts are pre-deployed with 100 dummy ETH in each.
20+
When you launch starknet-devnet-rs, 10 accounts are pre-deployed with 100 dummy ETH in each.
2121

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

24-
> This data will change at each launch, so to freeze them, launch with: `starknet-devnet --seed 0`.
24+
> This data will change at each launch, so to freeze them, launch with: `cargo run --release -- --seed 0`.
2525
2626
The result for `account #0`:
2727

28-
```bash
29-
Address: 0x7e00d496e324876bbc8531f2d9a82bf154d1a04a50218ee74cdd372f75a551a
30-
Public key: 0x7e52885445756b313ea16849145363ccb73fb4ab0440dbac333cf9d13de82b9
31-
Private key: 0xe3e70682c2094cac629f6fbed82c07cd
28+
```text
29+
Address : 0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691
30+
Private key: 0x71d7bb07b9a64f6f78ac4c816aff4da9
31+
Public key : 0x7e52885445756b313ea16849145363ccb73fb4ab0440dbac333cf9d13de82b9
3232
```
3333

3434
Then you can use this code:
3535

3636
```typescript
3737
// initialize provider
38-
const provider = new Provider({ sequencer: { baseUrl:"http://127.0.0.1:5050" } });
38+
const provider = new RpcProvider({ nodeUrl: "http://127.0.0.1:5050/rpc" });
3939
// initialize existing pre-deployed account 0 of Devnet
40-
const privateKey = "0xe3e70682c2094cac629f6fbed82c07cd";
41-
const accountAddress = "0x7e00d496e324876bbc8531f2d9a82bf154d1a04a50218ee74cdd372f75a551a";
40+
const privateKey = "0x71d7bb07b9a64f6f78ac4c816aff4da9";
41+
const accountAddress = "0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691";
4242

4343
const account = new Account(provider, accountAddress, privateKey);
4444
```
@@ -68,7 +68,7 @@ import * as dotenv from "dotenv";
6868
dotenv.config();
6969

7070
// initialize provider
71-
const provider = new Provider({ sequencer: { network: constants.NetworkName.SN_GOERLI } });
71+
const provider = new RpcProvider({ nodeUrl: `${myNodeUrl}` });
7272
// initialize existing account
7373
const privateKey = process.env.OZ_NEW_ACCOUNT_PRIVKEY;
7474
const accountAddress = "0x051158d244c7636dde39ec822873b29e6c9a758c6a9812d005b6287564908667";

www/docs/guides/connect_contract.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ You need 2 pieces of data:
1111
- the address of the contract
1212
- the ABI file of the contract (or the compiled/compressed contract file, that includes the abi)
1313

14-
> 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:
14+
> 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:
1515
1616
```typescript
1717
import fs from "fs";
18+
1819
const compressedContract = await provider.getClassAt(addrContract);
1920
fs.writeFileSync('./myAbi.json', json.stringify( compressedContract.abi, undefined, 2));
2021
```
@@ -24,7 +25,7 @@ fs.writeFileSync('./myAbi.json', json.stringify( compressedContract.abi, undefin
2425
## Get the abi from a compiled/compressed file
2526

2627
```typescript
27-
import { Provider, Contract, json } from "starknet";
28+
import { RpcProvider, Contract, json } from "starknet";
2829
```
2930

3031
If you have the compiled/compressed file of the contract, use this code to recover all data, including the ABI:
@@ -39,7 +40,7 @@ const compiledContract = json.parse(fs.readFileSync("./compiledContracts/test.js
3940

4041
```typescript
4142
// initialize provider
42-
const provider = new Provider({ sequencer: { network: constants.NetworkName.SN_GOERLI } });
43+
const provider = new RpcProvider({ nodeUrl: `${myNodeUrl}` });
4344

4445
// initialize deployed contract
4546
const testAddress = "0x7667469b8e93faa642573078b6bf8c790d3a6184b2a1bb39c5c923a732862e1";

www/docs/guides/connect_network.md

Lines changed: 52 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,131 +2,107 @@
22
sidebar_position: 3
33
---
44

5-
# Provider object 🔌 connect to the network
5+
# RpcProvider object 🔌 connect to the network
66

77
The first thing to do is to define with which network you want to interact.
88

9-
With the Provider object, you define which network to use.
9+
Then you need to select a node. A node is a safe way to connect with the Starknet blockchain. You can use:
1010

11-
```typescript
12-
import {Provider} from 'starknet';
13-
```
14-
15-
## Connect your DAPP to Starknet mainnet
16-
17-
```typescript
18-
const provider = new Provider({ sequencer: { network: constants.NetworkName.SN_MAIN } })
19-
```
20-
21-
## Connect your DAPP to Starknet testnet
22-
23-
```typescript
24-
const provider = new Provider({ sequencer: { network: constants.NetworkName.SN_GOERLI } }) // for testnet
25-
```
11+
- a node supplied by a node provider - it can be free or not; it can have limitations or not; it can have WebSocket support or not.
12+
> RPC node providers are for example Infura, Alchemy, Blast, Nethermind, Lava, Chainstack...
13+
- your own node, located on your local computer or in your local network.
14+
> you can spin up your own node with Pathfinder, Juno, Papyrus, Deoxys, ...
15+
- a local development node, that simulates a Starknet network. Useful for devs to perform quick tests without spending precious fee token.
16+
> Main development devnets are Starknet-devnet-rs, Madara, ...
2617
27-
## Connect your DAPP to Starknet devnet
18+
With the RpcProvider object, you define the Starknet Rpc node to use.
2819

2920
```typescript
30-
const provider = new Provider({ sequencer: { baseUrl:"http://127.0.0.1:5050"} });
21+
import {RpcProvider} from 'starknet';
3122
```
3223

33-
> If you have customized host and port during starknet-devnet initialization, adapt in accordance to your script.
34-
35-
## Connect your DAPP to a private Starknet network
36-
37-
If necessary you can have full control of the network access (for example, for your company's private test network):
38-
39-
```typescript
40-
const provider = new Provider({
41-
sequencer: {
42-
baseUrl: 'https://mynetwork.mycompany.io',
43-
feederGatewayUrl: 'feeder_gateway',
44-
gatewayUrl: 'gateway',
45-
}
46-
})
47-
```
48-
49-
## Connect your DAPP to a Starknet node
50-
51-
### Pathfinder
52-
53-
For a local [Pathfinder](https://github.com/eqlabs/pathfinder) node:
24+
## Connect your DAPP to an RPC node provider
5425

55-
```typescript
56-
const provider = new Provider({ rpc: { nodeUrl: '127.0.0.1:9545/rpc/v0.4' } })
57-
```
26+
### Default Rpc node
5827

59-
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`).
60-
You can connect with:
28+
If you don't want to use a specific node, or to handle an API key, you can use by default:
6129

6230
```typescript
63-
const provider = new Provider({ rpc: { nodeUrl: '192.168.1.99:9545/rpc/v0.4' } })
31+
const myProvider = new RpcProvider({ nodeUrl: constants.NetworkName.SN_GOERLI });
32+
const myProvider = new RpcProvider({ nodeUrl: constants.NetworkName.SN_MAIN });
33+
// or
34+
const myProvider = new RpcProvider(); // Goerli
6435
```
6536

66-
### Juno
67-
68-
Initialize the provider with:
37+
> when using this syntax, a random public node will be selected.
6938
70-
```typescript
71-
const provider = new RpcProvider({ nodeUrl: 'http://127.0.0.1:6060' });
72-
```
39+
Using a specific nodeUrl is the better approach, as such a node will have fewer limitations and will be less crowded.
7340

74-
### Other node clients
41+
Some examples of RpcProvider instantiation to connect to RPC node providers:
7542

76-
Other examples (some need a secret key):
77-
78-
**Mainnet:**
43+
### Mainnet
7944

8045
```typescript
8146
// Infura node rpc for Mainnet:
8247
const providerInfuraMainnet = new RpcProvider({ nodeUrl: 'https://starknet-mainnet.infura.io/v3/' + infuraKey });
8348
// Blast node rpc for Mainnet:
84-
const providerBlastMainnet = new RpcProvider({ nodeUrl: 'https://starknet-mainnet.blastapi.io/' + blastKey + "/rpc/v0.4" });
49+
const providerBlastMainnet = new RpcProvider({ nodeUrl: 'https://starknet-mainnet.blastapi.io/' + blastKey + "/rpc/v0.5" });
8550
// Lava node rpc for Mainnet:
8651
const providerMainnetLava = new RpcProvider({ nodeUrl: "https://g.w.lavanet.xyz:443/gateway/strk/rpc-http/" + lavaMainnetKey });
8752
// Alchemy node rpc for Mainnet:
88-
const providerAlchemyMainnet = new RpcProvider({ nodeUrl: 'https://starknet-mainnet.g.alchemy.com/v2/' + alchemyKey });
53+
const providerAlchemyMainnet = new RpcProvider({ nodeUrl: 'https://starknet-mainnet.g.alchemy.com/starknet/version/rpc/v0.5/' + alchemyKey });
54+
// Public Nethermind node rpc 0.5.1 for Mainnet:
55+
const providerMainnetNethermindPublic = new RpcProvider({ nodeUrl: "https://free-rpc.nethermind.io/mainnet-juno/v0_5" });
8956
```
9057

91-
**Testnet:**
58+
> Take care to safely manage your API key. It's a confidential item!
59+
60+
### Testnet
9261

9362
```typescript
9463
// Infura node rpc for Testnet:
9564
const providerInfuraTestnet = new RpcProvider({ nodeUrl: 'https://starknet-goerli.infura.io/v3/' + infuraKey });
9665
// Blast node rpc for Testnet:
97-
const providerBlastTestnet = new RpcProvider({ nodeUrl: 'https://starknet-testnet.blastapi.io/' + blastKey + "/rpc/v0.4" });
66+
const providerBlastTestnet = new RpcProvider({ nodeUrl: 'https://starknet-testnet.blastapi.io/' + blastKey + "/rpc/v0.5" });
9867
// Alchemy node rpc for Testnet:
99-
const providerAlchemyTestnet = new RpcProvider({ nodeUrl: 'https://starknet-goerli.g.alchemy.com/v2/' + alchemyKey });
68+
const providerAlchemyTestnet = new RpcProvider({ nodeUrl: 'https://starknet-goerli.g.alchemy.com/starknet/version/rpc/v0.5/' + alchemyKey });
69+
// Public Nethermind node rpc for Testnet:
70+
const providerTestnetNethermindPublic = new RpcProvider({ nodeUrl: "https://free-rpc.nethermind.io/testnet-juno/v0_5" });
10071
```
10172

102-
## Specific methods
73+
## Connect to your own node
10374

104-
Some methods are available only if connected to a sequencer, and some others are available only if connected to a node (using RPC).
75+
### Pathfinder
76+
77+
For a local [Pathfinder](https://github.com/eqlabs/pathfinder) node:
10578

106-
### Specific sequencer methods
79+
```typescript
80+
const provider = new RpcProvider({ nodeUrl: '127.0.0.1:9545/rpc/v0.5' });
81+
```
10782

108-
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:
83+
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`).
84+
You can connect with:
10985

11086
```typescript
111-
import { SequencerProvider, constants } from "starknet";
112-
const provider = new SequencerProvider({ baseUrl: constants.BaseUrl.SN_GOERLI }); // for testnet
113-
const responseEstimateMessageFee = await provider.estimateMessageFee(.....)
87+
const provider = new RpcProvider({ nodeUrl: '192.168.1.99:9545/rpc/v0.5' })
11488
```
11589

116-
### Specific RPC methods
90+
### Juno
11791

118-
For example, if you want to read the list of pending transactions, you need to use a method available from an RPC node. The class `RpcProvider` is available for this case:
92+
For a local [Juno](https://github.com/NethermindEth/juno) node initialize the provider with:
11993

12094
```typescript
121-
import { RpcProvider } from "starknet";
122-
const providerRPC = new RpcProvider({ nodeUrl: "http://192.168.1.99:9545/rpc/v0.4" }); // for a pathfinder node located in a PC in the local network
123-
const pendingTx = await providerRPC.getPendingTransactions();
95+
const provider = new RpcProvider({ nodeUrl: 'http://127.0.0.1:6060/v0_5' });
12496
```
12597

126-
RPC providers are for example Infura, Alchemy, Chainstack... Or you can spin up your own Pathfinder node!
98+
> 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.
99+
100+
## Devnet
127101

128-
For example, to connect to Alchemy with your personal API key:
102+
Example of a connection to a local development node, with Starknet-devnet-rs:
129103

130104
```typescript
131-
const providerRPC = new RpcProvider({ nodeUrl: 'https://starknet-mainnet.g.alchemy.com/v2/' + alchemyKey});
105+
const provider = new RpcProvider({ nodeUrl: "http://127.0.0.1:5050/rpc" });
132106
```
107+
108+
> If you have customized host and port during starknet-devnet initialization, adapt in accordance to your script.

www/docs/guides/create_account.md

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ Here, we will create a wallet with the Open Zeppelin smart contract v0.5.1. The
2424
This contract is coded in Cairo 0, so it will not survive the upcoming re-genesis of Starknet.
2525

2626
```typescript
27-
import { Account, constants, ec, json, stark, Provider, hash, CallData } from "starknet";
27+
import { Account, constants, ec, json, stark, RpcProvider, hash, CallData } from "starknet";
2828
```
2929

3030
### compute address
3131

3232
```typescript
3333
// connect provider
34-
const provider = new Provider({ sequencer: { network: constants.NetworkName.SN_GOERLI } });
34+
const provider = new RpcProvider({ nodeUrl: `${myNodeUrl}` });
3535

3636
// new Open Zeppelin account v0.5.1
3737
// Generate public and private key pair.
@@ -85,14 +85,6 @@ await provider.waitForTransaction(transaction_hash);
8585
console.log('✅ New OpenZeppelin account created.\n address =', contract_address);
8686
```
8787

88-
> **IMPORTANT:** If this account is based on a Cairo v2 contract (for example OpenZeppelin account 0.7.0 or later), do not forget to add the parameter "1" after the privateKey parameter:
89-
90-
```typescript
91-
const OZaccount = new Account(provider, OZcontractAddress, privateKey, "1");
92-
```
93-
94-
> Take care that this added parameter is a string, NOT a number.
95-
9688
## Create an Argent account
9789

9890
> Level: medium.
@@ -102,14 +94,14 @@ Here, we will create a wallet with the Argent smart contract v0.2.3. This case i
10294
> If necessary OZ contracts can also be created with a proxy.
10395
10496
```typescript
105-
import { Account, ec, json, stark, Provider, hash, CallData } from "starknet";
97+
import { Account, ec, json, stark, RpcProvider, hash, CallData } from "starknet";
10698
```
10799

108100
### compute address
109101

110102
```typescript
111103
// connect provider
112-
const provider = new Provider({ sequencer: { network: constants.NetworkName.SN_GOERLI } });
104+
const provider = new RpcProvider({ nodeUrl: `${myNodeUrl}` });
113105

114106
//new Argent X account v0.2.3
115107
const argentXproxyClassHash = "0x25ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918";
@@ -172,7 +164,7 @@ starknet-devnet --seed 0 --fork-network alpha-goerli
172164
Initialization:
173165

174166
```typescript
175-
import { Provider, Account, num, stark } from "starknet";
167+
import { RpcProvider, Account, num, stark } from "starknet";
176168
import { calculateAddressBraavos,
177169
deployBraavosAccount,
178170
estimateBraavosAccountDeployFee
@@ -195,8 +187,8 @@ const privateKeyBraavos = "0x02e8....e12";
195187
### Compute address
196188

197189
```typescript
198-
// initialize Provider
199-
const providerDevnet = new Provider({ sequencer: { baseUrl: "http://127.0.0.1:5050" } });
190+
// initialize provider
191+
const providerDevnet = new RpcProvider({ nodeUrl: `${myNodeUrl}` });
200192
// address
201193
const BraavosProxyAddress = calculateAddressBraavos(privateKeyBraavos);
202194
console.log('Calculated account address=', BraavosProxyAddress);
@@ -259,14 +251,14 @@ Here is an example of a customized wallet, including super administrator managem
259251
> launch `starknet-devnet --seed 0` before using this script
260252
261253
```typescript
262-
import { Account, ec, json, stark, Provider, hash, CallData } from "starknet";
254+
import { Account, ec, json, stark, RpcProvider, hash, CallData } from "starknet";
263255
import fs from "fs";
264256
import axios from "axios";
265257
```
266258

267259
```typescript
268260
// connect provider
269-
const provider = new Provider({ sequencer: { network: "http://127.0.0.1:5050" } });
261+
const provider = new RpcProvider({ network: "http://127.0.0.1:5050/rpc" });
270262

271263
// initialize existing predeployed account 0 of Devnet
272264
const privateKey0 = "0xe3e70682c2094cac629f6fbed82c07cd";

0 commit comments

Comments
 (0)