diff --git a/canister_ids.json b/canister_ids.json index e53f02f..92cf3a1 100644 --- a/canister_ids.json +++ b/canister_ids.json @@ -1,5 +1,8 @@ { "endpoint": { "ic": "3ondx-siaaa-aaaam-abf3q-cai" + }, + "eth": { + "ic": "kq5hz-ziaaa-aaaam-abnda-cai" } } \ No newline at end of file diff --git a/examples/example.rs b/examples/example.rs index 8a0b4e3..77900cf 100644 --- a/examples/example.rs +++ b/examples/example.rs @@ -9,12 +9,13 @@ 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 = std::result::Result; @@ -22,20 +23,19 @@ type Result = std::result::Result; #[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) -> Result { +async fn get_block(number: u64) -> Result { 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()); @@ -246,4 +246,4 @@ fn main() { } #[cfg(any(target_arch = "wasm32", test))] -fn main() {} \ No newline at end of file +fn main() {} diff --git a/examples/ic_web3.did b/examples/ic_web3.did index 0cbb990..9f517e0 100644 --- a/examples/ic_web3.did +++ b/examples/ic_web3.did @@ -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);