Methods

Here are the methods provided by the Wepin Flutter Widget SDK.

getStatus

await wepinSDK.getStatus()

Returns the lifecycle status of the WepinSDK.

Parameters

  • None

Return value

  • Future<WepinLifeCycle>

    • notInitialized: WepinSDK has not been initialized.

    • initializing: WepinSDK is in the process of initializing.

    • initialized: WepinSDK has been successfully initialized.

    • beforeLogin: WepinSDK is initialized, but the user is not logged in.

    • login: The user is logged in and registered with Wepin.

    • loginBeforeRegister: The user is logged in but not registered with Wepin.

Example

final status = await wepinSDK.getStatus();

login

The login variable is a Wepin login library that includes various authentication methods, allowing users to log in using different approaches. It supports email and password login, OAuth provider login, login using ID tokens or access tokens, and more. For detailed information on each method, refer to the official Login Library guide.

Available Methods

These methods support various login scenarios, allowing you to select the appropriate method based on your needs.

Exception

Example

// Login using an OAuth provider
final oauthResult = await wepinSDK.login.loginWithOauthProvider(provider: 'google', clientId: 'your-client-id');

// Sign up and log in using email and password
final signUpResult = await wepinSDK.login.signUpWithEmailAndPassword(email: 'example@example.com', password: 'password123');

// Log in using an ID token
final idTokenResult = await wepinSDK.login.loginWithIdToken(idToken: 'your-id-token', sign: 'your-sign');

// Log in to Wepin
final wepinLoginResult = await wepinSDK.login.loginWepin(idTokenResult);

// Get the currently logged-in user
final currentUser = await wepinSDK.login.getCurrentWepinUser();

// Logout
await wepinSDK.login.logout();

loginWithUI

await wepinSDK.loginWithUI(BuildContext context, {required List<LoginProvider> loginProviders, String? email})

The loginWithUI() method provides the functionality to log in using a widget and returns the information of the logged-in user. If a user is already logged in, the widget will not be displayed, and the method will directly return the logged-in user's information. To perform a login without the widget, use the loginWepin() method from the login variable instead.

This method can only be used after the authentication key has been deleted from the Wepin Workspace. (Wepin Workspace > Development Tools menu > Login tab > Auth Key > Delete)

The Auth Key menu is visible only if an authentication key was previously generated.

Supported Version Supported from version 0.0.4 and later.

Parameters

  • context <BuildContext> In Flutter, context represents the location within the widget tree, allowing you to locate widgets, access theme data, and handle navigation. When calling loginWithUI, you should pass the current context to ensure that the widget is displayed in the correct part of the UI hierarchy.

  • loginProviders<List<LoginProvider>> - An array of login providers to configure the widget. If an empty array is provided, only the email login function is available.

    • provider <String> The OAuth login provider (e.g., 'google', 'naver', 'discord', 'apple').

    • clientId <String> The client ID of the OAuth login provider.

  • email<String> optional The email parameter allows users to log in using the specified email address when logging in through the widget.

To use OAuth login functionality (e.g., loginWithUI), you need to configure OAuth login providers. You must first register your OAuth login provider information in the Wepin Workspace. For more details on setting up OAuth providers, refer to the Social Login OAuth Providers documentation.

Return Value

  • Future<WepinUser>

    • status <String> Indicates success or failure ('success'|'fail').

    • userInfo <WepinUserInfo> optional - User information.

      • userId <String>

        Wepin user ID.

      • email <String>

        The email address of the user logged in to Wepin.

      • provider <String>

        Login provider ('google'|'apple'|'naver'|'discord'|'email'|'external_token').

      • use2FA <bool>

        Indicates whether 2FA is enabled on the user’s wallet.

    • userStatus <WepinUserStatus>: User status.

      • loginStatus <String>

        Login status ('complete' | 'pinRequired' | 'registerRequired'). If the user's loginStatus is not 'complete', they need to register with Wepin.

      • pinRequired <bool>optional Indicates if a PIN is required.

    • walletId <String> Wepin user’s wallet ID.

    • token <WepinToken> Wepin token information.

Exception

Example

// google, apple, discord, naver login
final res = await wepinSDK.loginWithUI(context,
  loginProviders: [
    {
      provider: 'google',
      clientId: 'google-client-id'
    },
    {
      provider: 'apple',
      clientId: 'apple-client-id'
    },
    {
      provider: 'discord',
      clientId: 'discord-client-id'
    },
    {
      provider: 'naver',
      clientId: 'naver-client-id'
    },
  ]);

// only email login
final res = await wepinSDK.loginWithUI(context,
  loginProviders: []);

//with specified email address
final res = await wepinSDK.loginWithUI(context,
  loginProviders: [], email: 'abc@abc.com');
  
if(res.userStatus.loginStatus != "complete"){
    final userInfo  = await wepinSDK.register(context);
}

openWidget

await wepinSDK.openWidget(BuildContext context)

Opens the widget window. If the user is not logged in, the widget window will not open. Therefore, the user must be logged in to Wepin before calling openWidget. To log in to Wepin, use the loginWithUI or loginWepin method from the login variable.

Parameters

  • context <BuildContext> Represents the location of a widget in the widget tree in Flutter. This context is used to locate the widget’s position and to provide various functions like navigation, accessing theme data, and more. When calling openWidget, pass the current context to ensure the widget is displayed within the correct part of the UI hierarchy.

Return Value

  • Future<void>

Exception

Example

await wepinSDK.openWidget(context);

closeWidget

wepinSDK.closeWidget()

Closes the widget window. Closing the window does not log out the user.

Parameters

  • None

Return Value

  • void

Exception

Example

wepinSDK.closeWidget();

register

await wepinSDK.register(BuildContext context)

Registers the user with Wepin. After signing up and logging in, the Wepin widget’s registration page opens, allowing the user to register (create a wallet and account) with Wepin services. This function can only be used when WepinLifeCycle is loginBeforeRegister. After calling the loginWepin() method from the login variable, if the loginStatus value in userStatus is not 'complete', this method should be called.

Parameters

  • context <BuildContext> Represents the location of a widget in the widget tree. It is used to locate the widget's position in the tree and to provide various functions like navigation and accessing theme data. Pass the current context when calling register to ensure the widget is displayed in the correct part of the UI hierarchy.

Return Value

  • Future<WepinUser>

    • status <String> Indicates success or failure ('success'|'fail').

    • userInfo <WepinUserInfo> optional - User information.

      • userId <String>

        Wepin user ID.

      • email <String>

        The email address of the user logged in to Wepin.

      • provider <String>

        Login provider ('google'|'apple'|'naver'|'discord'|'email'|'external_token').

      • use2FA <bool>

        Indicates whether 2FA is enabled on the user’s wallet.

    • userStatus <WepinUserStatus>: User status.

      • loginStatus <String>

        Login status ('complete' | 'pinRequired' | 'registerRequired'). If the user's loginStatus is not 'complete', they need to register with Wepin.

      • pinRequired <bool>optional Indicates if a PIN is required.

    • walletId <String> Wepin user’s wallet ID.

    • token <WepinToken> Wepin token information.

Exception

Example

final userInfo = await wepinSDK.register(context);

getAccounts

await wepinSDK.getAccounts({List<String>? networks, bool? withEoa})

Returns the user's account information (networks and addresses) available in the app. This function can only be used after logging in to Wepin. If no parameters are provided, it returns information for all the user's accounts.

Parameters

  • networks <List<String>> optional The networks for which you want to return account information. The supported blockchain networks can be found on the supported blockchain page.

  • withEoa <bool> optional If AA accounts are present, this determines whether to include EOA accounts in the return.

Return Value

  • Future <List<WepinAccount>>

    • address <String> User account address.

    • network <String>

      The network type of the user's account.

    • contract <String> optional The contract address of the token.

    • isAA <bool> optional Indicates if it is an AA account.

Exception

Example

final result = await wepinSDK.getAccounts(
  networks: ['Ethereum'], 
  withEoa: true
);
  • response

[
  WepinAccount(
    address: "0x0000001111112222223333334444445555556666",
    network: "Ethereum",
  ),
  WepinAccount(
    address: "0x0000001111112222223333334444445555556666",
    network: "Ethereum",
    contract: "0x777777888888999999000000111111222222333333",
  ),
  WepinAccount(
    address: "0x4444445555556666000000111111222222333333",
    network: "Ethereum",
    isAA: true,
  ),
]

getBalance

await wepinSDK.getBalance({List<WepinAccount>? accounts})

Returns the balance information (amount) of accounts. This function can only be used after logging in to Wepin. If no accounts parameter is provided, it returns the balance of all user accounts.

Parameters

  • accounts <List<WepinAccount>> optional

    • network <String>

      The network type of the account for which to check the balance.

    • address <String>

      The address of the account for which to check the balance.

    • isAA <bool>optional Indicates if it is an AA account.

Return Value

  • Future <List<WepinAccountBalanceInfo>>

    • network <String>

      The network type of the user's account.

    • address <String>

      The address of the user's account.

    • symbol <String>

      Network symbol.

    • balance <String>

      The amount of the network coin held.

    • tokens <List<WepinTokenBalanceInfo>>

      • symbol <String>

        Token symbol.

      • balance <String>

        The amount of the token held.

      • contract <String>

        Token contract address.

Exception

Example

final result = await wepinSDK.getBalance([WepinAccount(
  address: '0x0000001111112222223333334444445555556666',
  network: 'Ethereum',
)]);
  • response

[
    WepinAccountBalanceInfo(
        network: "Ethereum",
        address: "0x0000001111112222223333334444445555556666",
        symbol: "ETH",
        balance: "1.1",
        tokens:[
            WepinTokenBalanceInfo(
                contract: "0x123...213",
                symbol: "TEST",
                balance: "10"
            ),
        ]
    )
]

getNFTs

await wepinSDK.getNFTs({required bool refresh, List<String>? networks})

Returns the user's NFTs. This function can only be used after logging in to Wepin. If no networks parameter is provided, it returns all of the user's NFT information.

Parameters

  • refresh <bool> Required parameter to indicate whether to refresh the NFT data.

  • networks <List<String>> optional A list of network names to filter the NFTs.

Return Value

  • Future<List<WepinNFT>>

    • account <WepinAccount>

      • address <String> User account address.

      • network <String> The network type of the user's account.

      • contract <String> optional Token contract address.

      • isAA <bool> optional Indicates if it is an AA account.

    • contract <WepinNFTContract>

      • name <String> NFT contract name.

      • address <String> NFT contract address.

      • scheme <String> Scheme of the NFT.

      • description <String> optional Description of the NFT contract.

      • network <String> Network associated with the NFT contract.

      • externalLink <String> optional External link associated with the NFT contract.

      • imageUrl <String> optional Image URL associated with the NFT contract.

    • name <String> Name of the NFT.

    • description <String> Description of the NFT.

    • externalLink <String> External link associated with the NFT.

    • imageUrl <String> Image URL associated with the NFT.

    • contentUrl <String> optional URL pointing to the content associated with the NFT.

    • quantity <int> Quantity of the NFT.

    • contentType <String> Content type of the NFT ('image' | 'video').

    • state <int> State of the NFT.

Exception

Example

final result = await wepinSDK.getNFTs(refresh: true, networks: ['Ethereum']);
  • Response

[
  WepinNFT(
    account: WepinAccount(
      address: "0x0000001111112222223333334444445555556666",
      network: "Ethereum",
      contract: "0x777777888888999999000000111111222222333333",
      isAA: true,
    ),
    contract: WepinNFTContract(
      name: "NFT Collection",
      address: "0x777777888888999999000000111111222222333333",
      scheme: "ERC721",
      description: "An example NFT collection",
      network: "Ethereum",
      externalLink: "https://example.com",
      imageUrl: "https://example.com/image.png",
    ),
    name: "Sample NFT",
    description: "A sample NFT description",
    externalLink: "https://example.com/nft",
    imageUrl: "https://example.com/nft-image.png",
    contentUrl: "https://example.com/nft-content.png",
    quantity: 1,
    contentType: "image/png",
    state: 0,
  ),
]

send

await wepinSDK.send(BuildContext context, {required WepinAccount account, WepinTxData? txData})

Performs the send function using the widget and returns the ID information of the send transaction. This function can only be used after logging in to Wepin.

Parameters

  • context <BuildContext> Represents the location of a widget in the widget tree in Flutter. This context is used to locate the widget’s position and to provide various functions like navigation, accessing theme data, and more. When calling send, pass the current context to ensure the widget is displayed within the correct part of the UI hierarchy.

  • account <WepinAccount> - The user's account information to send from.

    • network <String> The type of network to send to.

    • address <String> The address of the account to send to.

    • contract <String> optional The contract address of the token.

  • txData <WepinTxData> optional

    • to <String> The address to send to.

    • amount <String> The amount to send.

Return Value

  • Future <WepinSendResponse>

    • txId <string> The transaction ID of the send transaction.

Exception

Example

final result = await wepinSDK.send(context, {
    account: WepinAccount(
        address: '0x0000001111112222223333334444445555556666',
        network: 'Ethereum',
    ),
    txData: WepinTxData(
        to: '0x9999991111112222223333334444445555556666',
        amount: '0.1',
    )
})
// token send
final result = await wepinSDK.send(context, {
    account: WepinAccount(
        address: '0x0000001111112222223333334444445555556666',
        network: 'Ethereum',
        contract: '0x9999991111112222223333334444445555556666',
    ),
    txData: WepinTxData(
        to: '0x9999991111112222223333334444445555556666',
        amount: '0.1',
    )
})
  • response

WepinSendResponse(
    txId: "0x76bafd4b700ed959999d08ab76f95d7b6ab2249c0446921c62a6336a70b84f32"
)

receive

await wepinSDK.receive(BuildContext context, {required WepinAccount account})

The receive() method opens the account information page associated with the specified account. This method can only be used after logging into Wepin.

Supported Version Supported from version 0.0.4 and later.

Parameters

  • context <BuildContext> In Flutter, context represents the location within the widget tree, allowing you to locate widgets, access theme data, and handle navigation. When calling receive, you should pass the current context to ensure that the widget is displayed in the correct part of the UI hierarchy.

  • account <WepinAccount> - Provides the account information for the page that will be opened.

    • network <String> The network associated with the account.

    • address <String> The address of the account.

    • contract <String> optional The contract address of the token.

Return Value

  • Future<WepinReceiveResponse>

    • account <WepinAccount> - The account information of the page that was opened.

      • network <String> The network associated with the account.

        • address <String> The address of the account.

        • contract <String> optional The contract address of the token.

Exception

Example

// Opening an account page
final result = await wepinSDK.receive(context, {
    account: WepinAccount(
      address: '0x0000001111112222223333334444445555556666',
      network: 'Ethereum',
    ),
})

// Opening a token page
final result = await wepinSDK.receive(context, {
  account: WepinAccount(
    address: '0x0000001111112222223333334444445555556666',
    network: 'Ethereum',
    contract: '0x9999991111112222223333334444445555556666'
  ),
})

finalize

await wepinSDK.finalize()

Terminates the use of WepinSDK. The WepinLifeCycle changes to notInitialized.

Return Value

  • None

Example

await wepinSDK.finalize();

WepinError

Error CodeError MessageError Description

invalidAppKey

"InvalidAppKey"

The Wepin app key is invalid.

invalidParameters `

"InvalidParameters"

One or more parameters provided are invalid or missing.

invalidLoginProvider

"InvalidLoginProvider"

The login provider specified is not supported or is invalid.

invalidToken

"InvalidToken"

The token does not exist.

invalidLoginSession

"InvalidLoginSession"

The login session information does not exist.

notInitialized

"NotInitialized"

The WepinLoginLibrary has not been properly initialized.

alreadyInitialized

"AlreadyInitialized"

The WepinLoginLibrary is already initialized, so the logout operation cannot be performed again.

userCancelled

"UserCancelled"

The user has cancelled the operation.

unknownError

"UnknownError"

An unknown error has occurred, and the cause is not identified.

notConnectedInternet

"NotConnectedInternet"

The system is unable to detect an active internet connection.

failedLogin

"FailedLogin"

The login attempt has failed due to incorrect credentials or other issues.

alreadyLogout

"AlreadyLogout"

The user is already logged out, so the logout operation cannot be performed again.

invalidEmailDomain

"InvalidEmailDomain"

The provided email address's domain is not allowed or recognized by the system.

failedSendEmail

"FailedSendEmail"

The system encountered an error while sending an email. This is because the email address is invalid or we sent verification emails too often. Please change your email or try again after 1 minute.

requiredEmailVerified

"RequiredEmailVerified"

Email verification is required to proceed with the requested operation.

incorrectEmailForm

"incorrectEmailForm"

The provided email address does not match the expected format.

incorrectPasswordForm

"IncorrectPasswordForm"

The provided password does not meet the required format or criteria.

notInitializedNetwork

"NotInitializedNetwork"

The network or connection required for the operation has not been properly initialized.

requiredSignupEmail

"RequiredSignupEmail"

The user needs to sign up with an email address to proceed.

failedEmailVerified

"FailedEmailVerified"

The WepinLoginLibrary encountered an issue while attempting to verify the provided email address.

failedPasswordStateSetting

"FailedPasswordStateSetting"

Failed to set the password state. This error may occur during password management operations, potentially due to invalid input or system issues.

failedPasswordSetting

"failedPasswordSetting"

Failed to set the password. This could be due to issues with the provided password or internal errors during the password setting process.

existedEmail

"ExistedEmail"

The provided email address is already registered. This error occurs when attempting to sign up with an email that is already in use.

apiRequestError

"ApiRequestError"

There was an error while making the API request. This can happen due to network issues, invalid endpoints, or server errors.

incorrectLifecycleException

"IncorrectLifecycleException"

The lifecycle of the Wepin SDK is incorrect for the requested operation. Ensure that the SDK is in the correct state (e.g., initialized and login) before proceeding.

failedRegister

"FailedRegister"

Failed to register the user. This can occur due to issues with the provided registration details or internal errors during the registration process.

accountNotFound

"AccountNotFound"

The specified account was not found. This error is returned when attempting to access an account that does not exist in the Wepin.

nftNotFound

"NftNotFound"

The specified NFT was not found. This error occurs when the requested NFT does not exist or is not accessible within the user's account.

failedSend

"FailedSend"

Failed to send the required data or request. This error could be due to network issues, incorrect data, or internal server errors.

Last updated