Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate C-Chain Support in Avalanche Library #157

Merged
merged 4 commits into from
Jan 4, 2024

Conversation

leirbag95
Copy link
Contributor

Description

This pull request introduces a significant enhancement to the Avalanche library by integrating support for the C-Chain. The changes include the addition of a new enum ChainType, modification of the NewAccount function signature to include ChainType, and the introduction of a new function getEVMAddress specifically for the C-Chain.

Changes Made

  1. New Enum Added: ChainType

    • Introduced an enum ChainType with two values: C_CHAIN for the C-Chain and X_CHAIN for the X-Chain. This enum allows users to select the desired chain type easily.
      export enum ChainType {
          C_CHAIN = "C",
          X_CHAIN = "X",
      }
  2. Updated Function Signature: NewAccount

    • Modified the NewAccount function to include an optional parameter chain with a default value of ChainType.X_CHAIN. This change enables the creation of accounts specific to the selected chain type.
      export async function NewAccount(
          chain = ChainType.X_CHAIN,
      ): Promise<{ account: AvalancheAccount; privateKey: string }> {
          // Function implementation
      }
  3. New Function: getEVMAddress

    • Added a new function getEVMAddress to retrieve the EVM-compatible address for accounts associated with the C-Chain. This function ensures compatibility with Ethereum-style addresses and throws an error if the current signer is not associated with the C-Chain.
      /**
       * Retrieves the EVM compatible address for the current account.
       * This function works specifically with the C-Chain.
       *
       * If the current signer is not associated with the C-Chain,
       * the function throws an error.
       *
       * @returns A Promise that resolves to the EVM-style address of the account
       * @throws An error if the current signer is not associated with the C-Chain
       */
      async getEVMAddress(): Promise<string> {
          // Function implementation
      }

Impact

  • The addition of ChainType enum and the updated NewAccount function provide more flexibility and clarity for users interacting with different chains in the Avalanche ecosystem.
  • The getEVMAddress function enhances the library's capability to handle C-Chain specific operations, aligning with the growing demand for EVM compatibility.

@leirbag95 leirbag95 marked this pull request as draft December 23, 2023 14:55
Copy link
Member

@MHHukiewitz MHHukiewitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only nitpicking at this point, LGTM

src/accounts/avalanche.ts Outdated Show resolved Hide resolved
@MHHukiewitz MHHukiewitz marked this pull request as ready for review January 4, 2024 14:54
Copy link
Member

@MHHukiewitz MHHukiewitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MHHukiewitz MHHukiewitz merged commit dc5a82e into main Jan 4, 2024
2 of 5 checks passed
@MHHukiewitz MHHukiewitz deleted the feat/avalanche-c-chain branch January 4, 2024 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants