File tree Expand file tree Collapse file tree
modules/sdk-coin-evm/src/lib Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -272,3 +272,47 @@ export function validateHederaAccountId(address: string): { valid: boolean; erro
272272 error : null ,
273273 } ;
274274}
275+
276+ /**
277+ * Convert Hedera Account ID (e.g., 0.0.12345) to EVM address
278+ */
279+ export async function resolveHederaAccountIdToEvmAddress (
280+ accountId : string ,
281+ isProd : boolean
282+ ) : Promise < { address : string | null ; error ?: string } > {
283+ try {
284+ const mirrorNodeUrl = isProd
285+ ? 'https://mainnet-public.mirrornode.hedera.com'
286+ : 'https://testnet.mirrornode.hedera.com' ;
287+
288+ const response = await fetch ( `${ mirrorNodeUrl } /api/v1/accounts/${ accountId } ` ) ;
289+
290+ if ( ! response . ok ) {
291+ if ( response . status === 404 ) {
292+ return {
293+ address : null ,
294+ error : 'Hedera Account ID not found. Please verify the account exists.' ,
295+ } ;
296+ }
297+ return {
298+ address : null ,
299+ error : `Failed to resolve Hedera Account ID: ${ response . status } ` ,
300+ } ;
301+ }
302+
303+ const accountData = ( await response . json ( ) ) as { evm_address ?: string } ;
304+ if ( ! accountData . evm_address ) {
305+ return {
306+ address : null ,
307+ error : 'This Hedera account does not have an associated EVM address.' ,
308+ } ;
309+ }
310+
311+ return { address : accountData . evm_address } ;
312+ } catch ( error ) {
313+ return {
314+ address : null ,
315+ error : 'Failed to resolve Hedera Account ID. Please check your connection.' ,
316+ } ;
317+ }
318+ }
You can’t perform that action at this time.
0 commit comments