Skip to content

Commit

Permalink
implemented starknet_getChainId, starknet_syncing and starknet_getNon…
Browse files Browse the repository at this point in the history
…ce in starknet-rs for completeness
  • Loading branch information
saimeunt authored and jelilat committed Mar 10, 2024
1 parent 2952cca commit f1df770
Showing 1 changed file with 79 additions and 3 deletions.
82 changes: 79 additions & 3 deletions src/api/rpcspec/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,32 @@ async fn main() {
});
`,
starknetGo: ``,
starknetRs: ``,
starknetRs: `use starknet::{
providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Provider, Url,
},
};
#[tokio::main]
async fn main() {
let provider = JsonRpcClient::new(HttpTransport::new(
Url::parse("https://free-rpc.nethermind.io/mainnet-juno/").unwrap(),
));
let result = provider
.chain_id()
.await;
match result {
Ok(chain_id) => {
println!("{chain_id:#?}");
}
Err(err) => {
eprintln!("Error: {err}");
}
}
}
`,
},

// Returns an object about the sync status, or false if the node is not syncing
Expand All @@ -893,7 +918,31 @@ async fn main() {
});
`,
starknetGo: ``,
starknetRs: ``,
starknetRs: `use starknet::{
providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Provider, Url,
},
};
#[tokio::main]
async fn main() {
let provider = JsonRpcClient::new(HttpTransport::new(
Url::parse("https://free-rpc.nethermind.io/mainnet-juno/").unwrap(),
));
let result = provider
.syncing()
.await;
match result {
Ok(sync_status) => {
println!("{sync_status:#?}");
}
Err(err) => {
eprintln!("Error: {err}");
}
}
}`,
},

// Returns all events matching the given filter
Expand Down Expand Up @@ -980,7 +1029,34 @@ async fn main() {
});
`,
starknetGo: ``,
starknetRs: ``,
starknetRs: `use starknet::{
core::types::{BlockId, BlockTag},
macros::felt,
providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Provider, Url,
},
};
#[tokio::main]
async fn main() {
let provider = JsonRpcClient::new(HttpTransport::new(
Url::parse("https://free-rpc.nethermind.io/mainnet-juno/").unwrap(),
));
let result = provider
.get_nonce(BlockId::Tag(BlockTag::Latest), felt!("0x049D36570D4e46f48e99674bd3fcc84644DdD6b96F7C741B1562B82f9e004dC7"))
.await;
match result {
Ok(nonce) => {
println!("{nonce:#?}");
}
Err(err) => {
eprintln!("Error: {err}");
}
}
}
`,
},
];

Expand Down

0 comments on commit f1df770

Please sign in to comment.