diff --git a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/zks.rs b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/zks.rs index c0f80009dda..097dd047a77 100644 --- a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/zks.rs +++ b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/zks.rs @@ -146,7 +146,12 @@ impl ZksNamespaceT for ZksNamespa } fn get_native_token_address(&self) -> BoxFuture> { - todo!() + let self_ = self.clone(); + Box::pin(async move { + self_ + .get_native_token_address_impl() + .map_err(into_jsrpc_error) + }) } fn get_miniblock_range(&self, batch: L1BatchNumber) -> BoxFuture>> { diff --git a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpsee/namespaces/zks.rs b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpsee/namespaces/zks.rs index e93ea41bd26..5d2c165d1fa 100644 --- a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpsee/namespaces/zks.rs +++ b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpsee/namespaces/zks.rs @@ -39,7 +39,8 @@ impl ZksNamespaceServer for ZksNa } async fn get_native_token_address(&self) -> RpcResult
{ - todo!() + self.get_native_token_address_impl() + .map_err(into_jsrpc_error) } async fn get_testnet_paymaster(&self) -> RpcResult> { diff --git a/core/lib/zksync_core/src/api_server/web3/namespaces/zks.rs b/core/lib/zksync_core/src/api_server/web3/namespaces/zks.rs index b4d870a7d5a..875d177ce8c 100644 --- a/core/lib/zksync_core/src/api_server/web3/namespaces/zks.rs +++ b/core/lib/zksync_core/src/api_server/web3/namespaces/zks.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, convert::TryInto}; +use std::{collections::HashMap, convert::TryInto, fs::File, io::BufReader, str::FromStr}; use bigdecimal::{BigDecimal, Zero}; use zksync_dal::StorageProcessor; @@ -15,9 +15,9 @@ use zksync_types::{ l2_to_l1_log::L2ToL1Log, tokens::ETHEREUM_ADDRESS, transaction_request::CallRequest, - AccountTreeId, L1BatchNumber, MiniblockNumber, StorageKey, Transaction, L1_MESSENGER_ADDRESS, - L2_ETH_TOKEN_ADDRESS, MAX_GAS_PER_PUBDATA_BYTE, REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_BYTE, U256, - U64, + AccountTreeId, L1BatchNumber, MiniblockNumber, StorageKey, Transaction, H160, + L1_MESSENGER_ADDRESS, L2_ETH_TOKEN_ADDRESS, MAX_GAS_PER_PUBDATA_BYTE, + REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_BYTE, U256, U64, }; use zksync_utils::{address_to_h256, ratio_to_big_decimal_normalized}; use zksync_web3_decl::{ @@ -126,8 +126,23 @@ impl ZksNamespace { } #[tracing::instrument(skip_all)] - pub fn get_native_token_address_impl(&self) -> Address { - todo!() + pub fn get_native_token_address_impl(&self) -> Result { + const METHOD_NAME: &str = "get_native_token_address"; + const NATIVE_ERC20_FILE_PATH: &str = "etc/tokens/native_erc20.json"; + + // read the address from the native_erc20.json file. + // in the future it should be read from .init.env file + let native_erc20_file = + File::open(NATIVE_ERC20_FILE_PATH).map_err(|err| internal_error(METHOD_NAME, err))?; + let native_erc20_json: serde_json::Value = + serde_json::from_reader(BufReader::new(native_erc20_file)) + .map_err(|err| internal_error(METHOD_NAME, err))?; + + let native_erc20_address = native_erc20_json["address"] + .as_str() + .ok_or_else(|| internal_error(METHOD_NAME, "address not found in json"))?; + + H160::from_str(native_erc20_address).map_err(|err| internal_error(METHOD_NAME, err)) } #[tracing::instrument(skip(self))]