Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Jan 19, 2025
1 parent 886a737 commit a425f41
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions examples/json_abi.rs
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit a425f41

Please sign in to comment.