Skip to content

Commit

Permalink
create utility-functions example
Browse files Browse the repository at this point in the history
  • Loading branch information
strykerin committed Feb 11, 2025
1 parent fe8d02b commit 0a83aab
Show file tree
Hide file tree
Showing 3 changed files with 1,219 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/utility-functions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Import Push Chain SDK
import { CONSTANTS, PushChain } from '@pushchain/devnet';

// From CAIP-10 to UniversalAccount
const account = PushChain.utils.account.toUniversal(
'eip155:1:0x35B84d6848D16415177c64D64504663b998A6ab4'
);
console.log('From CAIP-10 to UniversalAccount:', account);

// From UniversalAccount to CAIP-10
const universalAccount = {
chain: CONSTANTS.CHAIN.ETHEREUM,
chainId: CONSTANTS.CHAIN_ID.ETHEREUM.SEPOLIA,
address: '0x35B84d6848D16415177c64D64504663b998A6ab4',
};

const caip10 = PushChain.utils.account.toChainAgnostic(universalAccount);
console.log('From UniversalAccount to CAIP-10:', caip10);

// Converts an EVM (Ethereum) address to a Push (bech32m) address
const pushAddr = PushChain.utils.account.evmToPushAddress(
'0x35B84d6848D16415177c64D64504663b998A6ab4'
);
console.log('From EVM (Ethereum) address to Push (bech32m) address:', pushAddr);

// Converts a Push (bech32m) address to an EVM (Ethereum) address
const evmAddr = PushChain.utils.account.pushToEvmAddress(
'push1xkuy66zg69jp29muvnty2prx8wvc5645f9y5ux'
);
console.log('From Push (bech32m) address to EVM (Ethereum) address:', evmAddr);
Loading

0 comments on commit 0a83aab

Please sign in to comment.