Skip to content

Commit

Permalink
deploy example to ic
Browse files Browse the repository at this point in the history
  • Loading branch information
ccyanxyz committed May 23, 2023
1 parent ab2c8ef commit 671b013
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
3 changes: 3 additions & 0 deletions canister_ids.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"endpoint": {
"ic": "3ondx-siaaa-aaaam-abf3q-cai"
},
"eth": {
"ic": "kq5hz-ziaaa-aaaam-abnda-cai"
}
}
18 changes: 9 additions & 9 deletions examples/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,33 @@ use ic_web3::ic::{get_eth_addr, KeyInfo};
use ic_web3::{
contract::{Contract, Options},
ethabi::ethereum_types::{U64, U256},
types::{Address, TransactionParameters, BlockId, BlockNumber},
types::{Address, TransactionParameters, BlockId},
};

const URL: &str = "https://ethereum.publicnode.com";
const CHAIN_ID: u64 = 1;
const KEY_NAME: &str = "dfx_test_key";
//const KEY_NAME: &str = "dfx_test_key";
const KEY_NAME: &str = "test_key_1";
const TOKEN_ABI: &[u8] = include_bytes!("../src/contract/res/token.json");

type Result<T, E> = std::result::Result<T, E>;

#[query(name = "transform")]
#[candid_method(query, rename = "transform")]
fn transform(response: TransformArgs) -> HttpResponse {
response.response
let mut t = response.response;
t.headers = vec![];
t
}

#[update(name = "get_block")]
#[candid_method(update, rename = "get_block")]
async fn get_block(number: Option<u64>) -> Result<String, String> {
async fn get_block(number: u64) -> Result<String, String> {
let w3 = match ICHttp::new(URL, None) {
Ok(v) => { Web3::new(v) },
Err(e) => { return Err(e.to_string()) },
};
let block_id = match number {
Some(id) => { BlockId::from(U64::from(id)) },
None => { BlockId::Number(BlockNumber::Latest) },
};
let block_id = BlockId::from(U64::from(number));
let block = w3.eth().block(block_id).await.map_err(|e| format!("get block error: {}", e))?;
ic_cdk::println!("block: {:?}", block.clone().unwrap());

Expand Down Expand Up @@ -246,4 +246,4 @@ fn main() {
}

#[cfg(any(target_arch = "wasm32", test))]
fn main() {}
fn main() {}
2 changes: 1 addition & 1 deletion examples/ic_web3.did
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Result = variant { Ok : text; Err : text };
type TransformArgs = record { context : vec nat8; response : HttpResponse };
service : {
batch_request : () -> (Result);
get_block : (opt nat64) -> (Result);
get_block : (nat64) -> (Result);
get_canister_addr : () -> (Result);
get_eth_balance : (text) -> (Result);
get_eth_gas_price : () -> (Result);
Expand Down

0 comments on commit 671b013

Please sign in to comment.