Class

WalletManager

WalletManager(env)

Constructor

# new WalletManager(env)

Create WalletManager instance object

Parameters:
Name Type Description
env EnvTypes

Environment types enum params (Ex: EnvTypes.DEV / EnvTypes.STAGING / EnvTypes.PREPROD / EnvTypes.PROD)

View Source modules/WalletManager.ts, line 10

Methods

# async connect() → {RegisteredUserData}

Perform the connection with current connected metamask account with browser's web session

View Source modules/WalletManager.ts, line 429

Exception: Need to select and connect to metamask accounts

string

Return the new users (wallet address, details info for wallet)

Example

Sample code

    // Sample code on staging:
    const walletManager = new WalletManager(EnvTypes.STAGING);
    const data = await walletManager.connect();
    console.log('Data ->', data);

    // Sample code on Production:
    const walletManager = new WalletManager(EnvTypes.PRODUCTION);
    const data = await walletManager.connect();
    console.log('Data ->', data);

# async connectAndLogin(userTypeopt, referrerIdopt) → {UserDataResponse|undefined}

Perform end to end registration process with metamask connection , connect wallet action and register user in Myria's system

Parameters:
Name Type Attributes Description
userType UserType <optional>

Type of user (PARTNER / CUSTOMER)

referrerId string <optional>

Game_ID / Project_ID / References Stark Key of another users if userType is customer

View Source modules/WalletManager.ts, line 498

Exception: ReferrerId is required!

string

Exception: Wallet registration failed: ${INTERNAL_SERVER_ERROR}

string

Exception: Register user failed: ${INTERNAL_SERVER_ERROR}

string

Exception: Cannot get user information with error: ${INTERNAL_SERVER_ERROR}

string

The details user data response for registration progress (including signature, stark key, wallet address)

UserDataResponse | undefined
Example

Sample code

    // Sample code on staging:
    const walletManager = new WalletManager(EnvTypes.STAGING);
    const registerUserData = await walletManager.connectAndLogin(
      UserType.PARTNER,
      '110', // Testnet (Staging) Project ID for the partner game
    );
    console.log('Testnet Data ->', registerUserData);

    // Sample code on Production:
    const walletManager = new WalletManager(EnvTypes.PRODUCTION);
    const registerUserData = await walletManager.connectAndLogin(
      UserType.PARTNER,
      '10', // Production Project ID for the partner game
    );
    console.log('Production Data ->', registerUserData);

# async getUserInfoByWalletAddress(ethAddress) → {UserDataResponse|undefined}

Perform the retrieve full user information by the Wallet address

Parameters:
Name Type Description
ethAddress string

The ether wallet address of user (such as Metamask wallet address)

View Source modules/WalletManager.ts, line 558

Exception: Eth address is required!

string

Http Status Code 404: User 0x... is not registered

string

Http Status Code 500: Get user data failed - unexpected with internal server error

string

Http Status Code 500: Internal Server Error with ${Exception}

string

The details user data response for registration progress (including signature, stark key, wallet address)

UserDataResponse | undefined
Example

Sample code

    // Sample code on staging:

    const walletManager = new WalletManager(EnvTypes.STAGING);

    const ethWalletAddress = '0x.....';
    const userWalletData = await walletManager.getUserInfoByWalletAddress(ethWalletAddress);
    console.log('Testnet Data ->', userWalletData);

    // Sample code on Production:
    const walletManager = new WalletManager(EnvTypes.PRODUCTION);

    const ethWalletAddress = '0x.....';
    const userWalletData = await walletManager.getUserInfoByWalletAddress(ethWalletAddress);
    console.log('Production Data ->', userWalletData);

# async getUserWalletByStarkKey(starkKey) → {UserDataResponse|undefined}

Perform the retrieve user wallet by the Stark Key

Parameters:
Name Type Description
starkKey string

Stark Key of user in L2 system of Myria

View Source modules/WalletManager.ts, line 528

Exception: Stark Key is required!

string

Http Status Code 404: User 0x... is not registered

string

Http Status Code 500: Get user data failed - unexpected with internal server error

string

Http Status Code 500: Internal Server Error with ${Exception}

string

The details user data response for registration progress (including signature, stark key, wallet address)

UserDataResponse | undefined
Example

Sample code

    // Sample code on staging:

    const walletManager = new WalletManager(EnvTypes.STAGING);

    const starkKey = '0x.....';
    const userWalletData = await walletManager.getUserWalletByStarkKey(starkKey);
    console.log('Testnet Data ->', userWalletData);

    // Sample code on Production:
    const walletManager = new WalletManager(EnvTypes.PRODUCTION);

    const starkKey = '0x.....';
    const userWalletData = await walletManager.getUserWalletByStarkKey(starkKey);
    console.log('Production Data ->', userWalletData);

# async registerAndLoginWithWalletAddress(walletAddress, userTypeopt, referrerIdopt) → {UserDataResponse|undefined}

The function required the wallet, and it performs full registration and normal login to get the user info data

Parameters:
Name Type Attributes Description
walletAddress string

Required metamask wallet address of user

userType UserType <optional>

Type of user for B2B (PARTNER) and B2C (CUSTOMER)

referrerId string <optional>

Referrer users to onboard to myria system. In case the type is partner, then the referrerID is PARTNER_GAME_NAME_ID or PROJECT_ID If type is customer, then the referrerID is stark key of referred's user

View Source modules/WalletManager.ts, line 466

Exception: Wallet address is required!

string

Exception: ReferrerId is required!

string

Exception: Wallet registration failed: ${INTERNAL_SERVER_ERROR}

string

Exception: Can't register the user with error: ${INTERNAL_SERVER_ERROR}

string

User data response (such as stark key, wallet address, registered signature)

UserDataResponse | undefined
Example

Sample code

    // Sample code on staging:
    const walletManager = new WalletManager(EnvTypes.STAGING);
    const data = await walletManager.registerAndLoginWithWalletAddress(
      '0xfb.....',       // wallet address
      UserType.PARTNER,  // User type as partner 
      '110', // Testnet (Staging) Project ID for the partner game
    );
    console.log('Testnet Data ->', data);

    // Sample code on Production:
    const walletManager = new WalletManager(EnvTypes.PRODUCTION);
    const data = await walletManager.registerAndLoginWithWalletAddress(
      '0xfb.....',       // wallet address
      UserType.PARTNER,  // User type as partner 
      '10', // Production Project ID for the partner game
    );
    console.log('Production Data ->', data);