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

chore: update examples to use jsonrpc and cairo 1 accounts #540

Merged
merged 1 commit into from
Feb 3, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Examples can be found in the [examples folder](./examples):

6. [Query the latest block number with JSON-RPC](./examples/jsonrpc.rs)

7. [Call a contract view function via sequencer gateway](./examples/sequencer_erc20_balance.rs)
7. [Call a contract view function](./examples/erc20_balance.rs)

8. [Deploy an Argent X account to a pre-funded address](./examples/deploy_argent_account.rs)

Expand Down
12 changes: 9 additions & 3 deletions examples/declare_cairo0_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use starknet::{
chain_id,
types::{contract::legacy::LegacyContractClass, BlockId, BlockTag, FieldElement},
},
providers::SequencerGatewayProvider,
providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Url,
},
signers::{LocalWallet, SigningKey},
};

Expand All @@ -15,7 +18,10 @@ async fn main() {
let contract_artifact: LegacyContractClass =
serde_json::from_reader(std::fs::File::open("/path/to/contract/artifact.json").unwrap())
.unwrap();
let provider = SequencerGatewayProvider::starknet_alpha_goerli();
let provider = JsonRpcClient::new(HttpTransport::new(
Url::parse("https://starknet-testnet.public.blastapi.io/rpc/v0_6").unwrap(),
));

let signer = LocalWallet::from(SigningKey::from_secret_scalar(
FieldElement::from_hex_be("YOUR_PRIVATE_KEY_IN_HEX_HERE").unwrap(),
));
Expand All @@ -26,7 +32,7 @@ async fn main() {
signer,
address,
chain_id::TESTNET,
ExecutionEncoding::Legacy,
ExecutionEncoding::New,
);

// `SingleOwnerAccount` defaults to checking nonce and estimating fees against the latest
Expand Down
12 changes: 9 additions & 3 deletions examples/declare_cairo1_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use starknet::{
chain_id,
types::{contract::SierraClass, BlockId, BlockTag, FieldElement},
},
providers::SequencerGatewayProvider,
providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Url,
},
signers::{LocalWallet, SigningKey},
};

Expand All @@ -21,7 +24,10 @@ async fn main() {
let compiled_class_hash =
FieldElement::from_hex_be("COMPILED_CASM_CLASS_HASH_IN_HEX_HERE").unwrap();

let provider = SequencerGatewayProvider::starknet_alpha_goerli();
let provider = JsonRpcClient::new(HttpTransport::new(
Url::parse("https://starknet-testnet.public.blastapi.io/rpc/v0_6").unwrap(),
));

let signer = LocalWallet::from(SigningKey::from_secret_scalar(
FieldElement::from_hex_be("YOUR_PRIVATE_KEY_IN_HEX_HERE").unwrap(),
));
Expand All @@ -32,7 +38,7 @@ async fn main() {
signer,
address,
chain_id::TESTNET,
ExecutionEncoding::Legacy,
ExecutionEncoding::New,
);

// `SingleOwnerAccount` defaults to checking nonce and estimating fees against the latest
Expand Down
10 changes: 8 additions & 2 deletions examples/deploy_argent_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use starknet::{
accounts::{AccountFactory, ArgentAccountFactory},
core::{chain_id, types::FieldElement},
macros::felt,
providers::SequencerGatewayProvider,
providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Url,
},
signers::{LocalWallet, SigningKey},
};

Expand All @@ -14,7 +17,10 @@ async fn main() {
// Anything you like here as salt
let salt = felt!("12345678");

let provider = SequencerGatewayProvider::starknet_alpha_goerli();
let provider = JsonRpcClient::new(HttpTransport::new(
Url::parse("https://starknet-testnet.public.blastapi.io/rpc/v0_6").unwrap(),
));

let signer = LocalWallet::from(SigningKey::from_secret_scalar(
FieldElement::from_hex_be("YOUR_PRIVATE_KEY_IN_HEX_HERE").unwrap(),
));
Expand Down
12 changes: 9 additions & 3 deletions examples/deploy_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use starknet::{
types::{contract::legacy::LegacyContractClass, BlockId, BlockTag, FieldElement},
},
macros::felt,
providers::SequencerGatewayProvider,
providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Url,
},
signers::{LocalWallet, SigningKey},
};

Expand All @@ -20,7 +23,10 @@ async fn main() {
.unwrap();
let class_hash = contract_artifact.class_hash().unwrap();

let provider = SequencerGatewayProvider::starknet_alpha_goerli();
let provider = JsonRpcClient::new(HttpTransport::new(
Url::parse("https://starknet-testnet.public.blastapi.io/rpc/v0_6").unwrap(),
));

let signer = LocalWallet::from(SigningKey::from_secret_scalar(
FieldElement::from_hex_be("YOUR_PRIVATE_KEY_IN_HEX_HERE").unwrap(),
));
Expand All @@ -30,7 +36,7 @@ async fn main() {
signer,
address,
chain_id::TESTNET,
ExecutionEncoding::Legacy,
ExecutionEncoding::New,
);

// `SingleOwnerAccount` defaults to checking nonce and estimating fees against the latest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
use starknet::{
core::types::{BlockId, BlockTag, FieldElement, FunctionCall},
macros::{felt, selector},
providers::{Provider, SequencerGatewayProvider},
providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Provider, Url,
},
};

#[tokio::main]
async fn main() {
let provider = SequencerGatewayProvider::starknet_alpha_goerli();
let provider = JsonRpcClient::new(HttpTransport::new(
Url::parse("https://starknet-testnet.public.blastapi.io/rpc/v0_6").unwrap(),
));

let tst_token_address =
felt!("0x07394cbe418daa16e42b87ba67372d4ab4a5df0b05c6e554d158458ce245bc10");

Expand Down
10 changes: 8 additions & 2 deletions examples/get_block.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
use starknet::{
core::types::{BlockId, BlockTag},
providers::{Provider, SequencerGatewayProvider},
providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Provider, Url,
},
};

#[tokio::main]
async fn main() {
let provider = SequencerGatewayProvider::starknet_alpha_goerli();
let provider = JsonRpcClient::new(HttpTransport::new(
Url::parse("https://starknet-testnet.public.blastapi.io/rpc/v0_6").unwrap(),
));

let latest_block = provider
.get_block_with_tx_hashes(BlockId::Tag(BlockTag::Latest))
.await;
Expand Down
12 changes: 5 additions & 7 deletions examples/jsonrpc.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use starknet_providers::{
use starknet::providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Provider,
Provider, Url,
};
use url::Url;

#[tokio::main]
async fn main() {
let rpc_client = JsonRpcClient::new(HttpTransport::new(
Url::parse("https://starknet-goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161")
.unwrap(),
let provider = JsonRpcClient::new(HttpTransport::new(
Url::parse("https://starknet-testnet.public.blastapi.io/rpc/v0_6").unwrap(),
));

let block_number = rpc_client.block_number().await.unwrap();
let block_number = provider.block_number().await.unwrap();
println!("{block_number}");
}
12 changes: 9 additions & 3 deletions examples/mint_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ use starknet::{
types::{BlockId, BlockTag, FieldElement},
utils::get_selector_from_name,
},
providers::SequencerGatewayProvider,
providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Url,
},
signers::{LocalWallet, SigningKey},
};

#[tokio::main]
async fn main() {
let provider = SequencerGatewayProvider::starknet_alpha_goerli();
let provider = JsonRpcClient::new(HttpTransport::new(
Url::parse("https://starknet-testnet.public.blastapi.io/rpc/v0_6").unwrap(),
));

let signer = LocalWallet::from(SigningKey::from_secret_scalar(
FieldElement::from_hex_be("YOUR_PRIVATE_KEY_IN_HEX_HERE").unwrap(),
));
Expand All @@ -26,7 +32,7 @@ async fn main() {
signer,
address,
chain_id::TESTNET,
ExecutionEncoding::Legacy,
ExecutionEncoding::New,
);

// `SingleOwnerAccount` defaults to checking nonce and estimating fees against the latest
Expand Down
Loading