From a425f41892b0d991ae45c83278174613879bfdee Mon Sep 17 00:00:00 2001 From: Ammar Arif Date: Sat, 18 Jan 2025 23:21:07 -0500 Subject: [PATCH] add example --- examples/json_abi.rs | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 examples/json_abi.rs diff --git a/examples/json_abi.rs b/examples/json_abi.rs new file mode 100644 index 0000000..e92aa8d --- /dev/null +++ b/examples/json_abi.rs @@ -0,0 +1,59 @@ +use cainome::rs::abigen; +use starknet::{ + macros::felt, + providers::{jsonrpc::HttpTransport, JsonRpcClient}, +}; +use url::Url; + +abigen!(MyContractFile, "./contracts/abi/simple_types.abi.json",); + +abigen!(MyContractEmbed, [ + { + "type": "function", + "name": "get_bool", + "inputs": [], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "set_bool", + "inputs": [ + { + "name": "v", + "type": "core::bool" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "get_felt", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + } +]); + +#[tokio::main] +async fn main() { + let url = Url::parse("http://localhost:5050").unwrap(); + let provider = JsonRpcClient::new(HttpTransport::new(url)); + + let contract = MyContractEmbedReader::new(felt!("0x1337"), &provider); + let _ = contract.get_bool().call().await.unwrap(); + let _ = contract.get_felt().call().await.unwrap(); + + let contract = MyContractFileReader::new(felt!("0x1337"), &provider); + let _ = contract.get_bool().call().await.unwrap(); + let _ = contract.get_felt().call().await.unwrap(); +}