LYNC
DashboardSupport
  • 👋Introducing LYNC
  • Products
    • LYNC Account Abstraction SDK
    • LYNC Account Abstraction WebGL SDK
    • Metamask Wallet
    • LYNC Metamask PC SDK
    • OKX Wallet
    • LYNC In-Game Marketplace SDK
    • NFT Fetcher
    • No-Code Smart Contract Deployer
    • EVM Lootbox SDK
      • Getting Started
      • Using the SDK
        • Creating a new lootbox
        • Opening a lootbox
        • Claiming rewards
        • Whitelisting users using lootbox
        • Lootbox admin functions
        • Useful information functions from LyncLootBox class
        • Multicall : opening and claiming multiple lootboxes in a single transaction
      • Example Codes in React & TypeScript
        • Example code for creating a new lootbox
        • Example code for opening a lootbox
        • Example code for claiming a lootbox
    • Launch your products on Telegram
      • Configure Your Telegram Bot
      • Deploying Your Product on TG
  • APTOS
    • LYNC Paymaster - Supporting Aptos
      • How to Register on LYNC Dashboard
      • How to Create Paymaster
      • How to Fund the Paymaster
      • Module & Function Whitelist
      • How to Integrate Paymaster
        • Unity
        • API
        • JavaScript/ TypeScript
    • LYNC Unity Aptos SDK
    • Keyless Accounts
      • Configure Your OIDC Provider
      • Integrate Keyless in Unity
    • Wallet Creation and Transaction APIs
      • Pre-requisites
      • Integration
        • API Overview
        • Create a new wallet
        • Get already created wallet
        • Mint NFT transactions
        • Send generic transactions on Aptos
    • LYNC Social Login SDK on Aptos
      • Getting Started
      • Using the SDK
      • Example Codes in React & TypeScript
      • Types Used in the Methods Provided by the SDK
      • Other Specification
    • LYNC Aptos Lootbox
      • Getting Started
      • Creating a Lootbox
      • Opening a Lootbox
      • Claiming the Rewards
      • Conclusion
  • Movement Labs
    • 📇Indexer
      • How to run index custom data?
      • Example Queries
        • Get Token Info
        • Get Token Balances
        • Get NFTs Owned by an Account
    • NFT Deployer
    • LYNC Social Login SDK on Movement
      • Getting Started
      • Using the SDK
      • Example Codes in React & TypeScript
      • Types and Enums Used in the Methods Provided by the SDK
      • Other Specification
    • LYNC Unity Movement SDK
    • Wallet Creation and Transaction APIs
      • Pre-requisites
      • Integration
        • API Overview
        • Create a new wallet
        • Get already created wallet
        • Mint NFT transactions
    • LYNC Paymaster - Supporting Movement
      • How to Register on LYNC Dashboard
      • How to Create Paymaster
      • How to Fund the Paymaster
      • Module & Function Whitelist
      • How to Integrate Paymaster
        • JavaScript/ TypeScript
  • Supra
    • LYNC Paymaster - Supporting Supra L1
      • How to Register on LYNC Dashboard
      • How to Create Paymaster
      • How to Fund the Paymaster
      • Module & Function Whitelist
      • How to Integrate Paymaster
        • JavaScript/ TypeScript
    • LYNC Unity SUPRA SDK
    • Wallet Creation and Transaction APIs
      • Pre-requisites
      • Integration
        • API Overview
        • Create a new wallet
        • Get already created wallet
        • Mint NFT transactions
  • Fuel
    • LYNC Unity Fuel SDK
    • LYNC NFT Deployer
      • Introduction
      • Getting Started
      • Deploying Your NFTs
        • Launch Your Entire Collection
      • Troubleshooting and FAQs
    • LYNC Fuel Lootbox
      • Getting Started
      • Creating a Lootbox
      • Opening a Lootbox
      • Claiming the Rewards
      • Conclusion
    • Wallet Creation and Transaction APIs
      • Pre-requisites
      • Integration
        • API Overview
        • Create a new wallet
        • Get already created wallet
    • Fuel Marketplace NPM SDK
      • Getting Started
      • Using the SDK
        • Using hooks to get the marketplace data
        • Using services provided by the SDK to list, buy, and manage tokens
        • Some useful functions provided by the SDK
        • Error codes for the SDK
        • Interfaces and Enums provided by the SDK
      • Support
  • Metis
    • Wallet Creation and Transaction APIs
      • Pre-requisites
      • Integration
        • API Overview
        • Create a new wallet
        • Get already created wallet
        • Mint NFT transactions
  • NPM Packages
    • Marketplace
      • Hook: useAllCollectionNFT
      • Hook: useAllBuyNFT
      • Hook: useAllOwnerNFT
      • Hook: useNFTDetails
      • Hook: useAllNFTForRent
Powered by GitBook
On this page
  • Functions Overview
  • 1. Authenticating user with Google Sign-In
  • 2. Signing Out a User
  • 3. Get the details of a User
  • 4. Generic Transactions on Aptos Blockchain
  1. APTOS
  2. LYNC Social Login SDK on Aptos

Example Codes in React & TypeScript

In this Section, you will see examples of how to use the functions provided by the SDK to integrate authentication, user management, and Aptos transaction execution into your React project. All the example uses TypeScript. However, the SDK can also be used with React and JavaScript in the same way, as shown in the examples.

Functions Overview

1. Authenticating user with Google Sign-In

// Function Signature -

const signInWithGoogle = (network: NetworkConfigs, apiKey: string, logEnabled?: boolean) => Promise<SignInWithGoogleReturn>

This function allows users to sign in with Google using OAuthProvider.

Parameters:

  • network: Network Type Enum.

  • apiKey : Your API key from generated from LYNC dashboard - https://dashboard.lync.world

  • logEnabled (Optional): Enable/disable logging. The default is true.

Return Type:

  • Promise<SignInWithGoogleReturn>:

    { success: true; user: UserData; } if successful.

    { success: false; message: string; } if unsuccessful.

Errors:

The function can throw an error if the sign-in operation fails. The error message is logged if logging is enabled.

Example:

Here is an example of a React component that imports and uses the signInWithGoogle function:

import React from "react";
import { signInWithGoogle } from "@lyncworld/aptos-social-login-sdk";

const SignInButton = () => {
  const handleSignIn = async () => {
    try {
      const response = await signInWithGoogle(NetworkConfigs.Testnet,"<YOUR_API_KEY>",true);
      if (response.success) {
        console.log("User data:", response.user);
      } else {
        console.log("Error:", response.message);
      }
    } catch (error) {
      console.error("An error occurred:", error);
    }
  };

  return <button onClick={handleSignIn}>Sign in with Google</button>;
};

export default SignInButton;

2. Signing Out a User

// Function Signature -

const signOutUser = (logEnabled?: boolean) => Promise<SignOutUserReturn>

This function is used to sign out a user from the application. It uses Firebase's signOut function to sign out the user.

Parameters:

  • logEnabled (Optional): Enable/disable logging. The default is true.

Return Type:

  • Promise<SignOutUserReturn>:

    { success: true; } if successful.

    { success: false; message: string; } if unsuccessful.

Errors:

The function can throw an error if the sign-out operation fails. The error message is logged if logging is enabled.

Example:

Here is an example of a React component that imports and uses the signOutUser function:

import React from "react";
import { signOutUser } from "@lyncworld/aptos-social-login-sdk";

const SignOutButton = () => {
  const handleSignOut = async () => {
    try {
      const response = await signOutUser(true);
      if (response.success) {
        console.log("User signed out successfully");
      } else {
        console.log("Error:", response.message);
      }
    } catch (error) {
      console.error("An error occurred:", error);
    }
  };

  return <button onClick={handleSignOut}>Sign out</button>;
};

export default SignOutButton;

3. Get the details of a User

// Function Signature -

const getUserProfile = (email: string, network: NetworkConfigs, apiKey: string, logEnabled?: boolean) => Promise<GetUserProfileReturn>

This function is an asynchronous function that fetches a user's profile from the server.

Parameters:

  • email: The email of the user.

  • network: Network Type Enum.

  • apiKey : Your API key from generated from LYNC dashboard - https://dashboard.lync.world

  • logEnabled (Optional): Enable/disable logging. The default is true.

Return Type:

  • Promise<GetUserProfileReturn>:

    { success: true; data: UserData; } if successful.

    { success: false; data: string; } if unsuccessful.

Errors:

The function can throw an error if the fetch operation fails. The error message is logged if logging is enabled.

Example:

Here is an example of a React component that imports and uses the getUserProfile function:

import React, { useEffect, useState } from "react";
import { getUserProfile } from "@lyncworld/aptos-social-login-sdk";

const UserProfileComponent = () => {
  const [userProfile, setUserProfile] = useState(null);

  useEffect(() => {
    const fetchUserProfile = async () => {
      const response = await getUserProfile("test@example.com",NetworkConfigs.Testnet,"<YOUR_API_KEY>");
      if (response.success) {
        setUserProfile(response.data);
      } else {
        console.error(response.message);
      }
    };

    fetchUserProfile();
  }, []);

  return (
    <div>
      {userProfile && (
        <div>
          <h2>{userProfile.name}</h2>
          <p>{userProfile.email}</p>
          {/* Render other user profile data as needed */}
        </div>
      )}
    </div>
  );
};

export default UserProfileComponent;

4. Generic Transactions on Aptos Blockchain

// Function Signature

const aptosTransaction = (args: AptosTransactionFuncArgs,apiKey: string,logEnabled?: boolean) => Promise<AptosTransactionReturn>

This is an asynchronous function that executes a generic Aptos transaction.

Parameters:

  • args (AptosTransactionFuncArgs): The arguments for the generic Aptos transaction. It is an object that includes the following properties:

    • email (string): The email of the user.

    • walletAddress (string): The wallet address of the currently signed-in user.

    • apiKey(string): Your API key from generated from LYNC dashboard - https://dashboard.lync.world

    • network (NetworkConfigs): Network Type Enum.

    • contractAddress (string): The contract address.

    • contractName (string): The contract name.

    • functionName (string): The function name.

    • arguments (Array): The arguments for the transaction. Each argument is an object that includes the following properties:

      • argument (string): The argument used by the function.

      • type (string): The type of the argument. It can be string, number, or byte_array.

    • usePaymaster (Optional): Enable/disable the use of paymaster. The default is false. If you enable paymaster the transaction will be sponsored. Also, if the wallet doesn't exist, it will be created automatically before the transaction.

  • apiKey: Your API key from generated from LYNC dashboard - https://dashboard.lync.world

  • logEnabled (Optional): Enable/disable logging. The default is true.

Return Type:

  • Promise<AptosTransactionReturn>:

    { success: true; data: AptosTransactionData; } if successful.

    { success: false; data: string; } if unsuccessful.

Errors:

The function can throw an error if the transaction fails. The error message is logged if logging is enabled.

Example:

Here is an example of a React component that imports and uses the aptosTransaction function to perform a simple transfer transaction:

import React, { useState } from "react";
import { aptosTransaction } from "@lyncworld/aptos-social-login-sdk";

const TransactionComponent = () => {
  const [transactionResult, setTransactionResult] = useState(null);

  const executeTransaction = async () => {
    const transactionArgs = {
      email: "user@example.com", // Email id of the sender
      walletAddress: "0x0000", // Public key of the sender
      apiKey: "<YOUR_API_KEY>",
      network: NetworkConfigs.Testnet
      contractAddress: "0x1",
      contractName: "aptos_account",
      functionName: "transfer",
      arguments: [
        {
          argument: "0x0000", // Wallet address of the receiver
          type: "string",
        },
        {
          argument: (1 * 10 ** 8).toString(), // Total APT to be transferred (Current argument will transfer 1 APT)
          type: "number",
        },
      ],
      usePaymaster: true, // Sponsor the transaction
    };

    const logEnabled = true;

    try {
      const response = await aptosTransaction(transactionArgs,"<YOUR_API_KEY>", logEnabled);
      setTransactionResult(response);
    } catch (error) {
      console.error("Error executing transaction:", error);
    }
  };

  return (
    <div>
      <button onClick={executeTransaction}>Execute Transaction</button>
      {transactionResult && (
        <div>
          <h2>Transaction Result:</h2>
          <p>Success: {transactionResult.success.toString()}</p>
          <p>Data: {JSON.stringify(transactionResult.data)}</p>
        </div>
      )}
    </div>
  );
};

export default TransactionComponent;
PreviousUsing the SDKNextTypes Used in the Methods Provided by the SDK

Last updated 3 months ago