or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

address.mdbase-encoding.mdcrypto-init.mdethereum.mdhashing.mdindex.mdjson-encryption.mdkey-derivation-pbkdf.mdkey-derivation.mdkeypairs.mdmnemonic.mdrandom.mdsignatures.md

ethereum.mddocs/

0

# Ethereum Compatibility

1

2

Ethereum address handling and compatibility utilities for cross-chain functionality and EVM integration.

3

4

## Capabilities

5

6

### Ethereum Address Encoding

7

8

Convert public keys and addresses to Ethereum format.

9

10

```typescript { .api }

11

/**

12

* Encode address or public key to Ethereum format

13

* @param addressOrPublic - SS58 address or public key bytes

14

* @returns Ethereum address (0x prefixed, 40 hex chars)

15

*/

16

function ethereumEncode(addressOrPublic: string | Uint8Array): string;

17

18

/**

19

* Check if string is valid Ethereum address

20

* @param address - Address string to check

21

* @returns true if valid Ethereum address format

22

*/

23

function isEthereumAddress(address: string): boolean;

24

25

/**

26

* Check Ethereum address checksum validity

27

* @param address - Ethereum address to validate

28

* @returns true if checksum is valid

29

*/

30

function isEthereumChecksum(address: string): boolean;

31

```

32

33

### Address Conversion

34

35

Convert between SS58 and EVM address formats.

36

37

```typescript { .api }

38

/**

39

* Convert SS58 address to EVM format

40

* @param address - SS58 address string

41

* @returns 20-byte EVM address

42

*/

43

function addressToEvm(address: string): Uint8Array;

44

45

/**

46

* Convert EVM address to SS58 format

47

* @param evmAddress - 20-byte EVM address

48

* @param prefix - SS58 network prefix

49

* @param hashType - Hash algorithm ('blake2' or 'keccak')

50

* @returns SS58 address string

51

*/

52

function evmToAddress(evmAddress: Uint8Array, prefix?: number, hashType?: 'blake2' | 'keccak'): string;

53

```

54

55

**Usage Examples:**

56

57

```typescript

58

import {

59

ethereumEncode,

60

isEthereumAddress,

61

addressToEvm,

62

evmToAddress,

63

sr25519PairFromSeed

64

} from "@polkadot/util-crypto";

65

66

// Generate Ethereum address from public key

67

const seed = new Uint8Array(32);

68

const pair = sr25519PairFromSeed(seed);

69

const ethAddress = ethereumEncode(pair.publicKey);

70

console.log(ethAddress); // "0x..."

71

72

// Validate Ethereum address

73

const isValid = isEthereumAddress("0x742d35Cc...49F8A26aE2");

74

console.log(isValid); // true

75

76

// Convert between formats

77

const ss58Address = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY";

78

const evmBytes = addressToEvm(ss58Address);

79

const backToSS58 = evmToAddress(evmBytes, 0, 'blake2');

80

```