Wallet SDK

This guide shows how to use standard web3 wallet functions

Every wallet needs to interact with the blockchain for carrying out various functions. Once the widget is embedded and the user connects their profile through their preferred auth method, a session is created for this user after which the standard wallet functions can be utilized.

AuthMethod

To create a wallet, user first needs to choose how do they want to create the wallet i.e. select their AuthMethod. Currently we support 3 auth methods (with support for more auth methods coming soon) i.e. gmail, email and metamask.

Once the user selects a certain auth method, a wallet is created in the network that makes sure that this wallet is accessible only with a valid login jwt of the selected auth method.

If the user uses an email for creation of a wallet and then later on selects gmail for that same email address, we do not create two separate wallets rather tag both authmethods to the same user. Currently no other embedded wallet products offer this feature, resulting in users regularly forgetting what they used to sign up to an application. We reduce this cognitive load for end users.

ProfileSession

After successful login of profile, a session is created that allows user to access the SDK functions. The session expires after a certain time or when the user logs out. Without valid session signatures, the MPC network will not allow for signature signing.

As soon as the login process is complete, the connect profile button will automatically change to a circular profile icon with the user's avatar in it and a dropdown with basic profile functions.

Wallet SDK

To access the wallet functions, the following import should be done on the page/component where the functions need to be called.

import { PluralitySocialConnect } from '@plurality-network/smart-profile-wallet';
import { 
            AllAccountsDataType, 
            ConnectedAccountDataType, 
            SignMessageDataType, 
            VerifySignedMessageDataType,
            GetBalanceDataType, 
            GetBlockNumberDataType, 
            GetTransactionCountDataType, 
            ReadFromContractDataType, 
            SendTransactionDataType, 
            WriteToContractDataType 
        } from '@plurality-network/smart-profile-wallet';

You can add/remove the types based on the functions you actually use on the page.

Clone our boilerplate to have a basic application with embedded widget and all the wallet functions already in there.

Once the application has access to a valid session i.e. the user has successfully logged in, the following wallet functions become accessible.

Get All Connected Accounts

Returns all connected accounts/addresses e.g. [0x123…, 0x456…].

const response = (await PluralitySocialConnect.getAllAccounts()) as AllAccountsDataType;

if (response) {
    const allAccounts = response.data;
    return allAccounts[0]?.address;
}

Get Current Connected Account

Get current account connected

const response = (await PluralitySocialConnect.getConnectedAccount()) as ConnectedAccountDataType;

if (response) {
    const connectedAccount = response.data;
    return connectedAccount?.address;
}

Get Signature

Gets the message signed using the connected account and returns the signature.

const response = (await PluralitySocialConnect.getMessageSignature(message)) as SignMessageDataType;
if (response) {
    const signMessage = response.data;
    return signMessage;
}

Verify Message Signature

Verify if the signature matches the message using the current connected account and returns boolean true or false.

const response = (await PluralitySocialConnect.verifyMessageSignature(message, key)) as VerifySignedMessageDataType;
if (response) {
    const verifyMessage = response.data;
    return verifyMessage;
}

Get Balance

Returns balance of the current account in wei. You need to convert it to the required denomination yourself.

Please note that since Plurality profiles are chain agnostic, you need to provide the RPC and the chainId to ensure that balance is being read from the current read. You can find the RPC and the chainId of your preferred chain through this link. We currently support only EVM-compatible chains.

const response = (await PluralitySocialConnect.getBalance(rpc, chainId)) as GetBalanceDataType;
if (response) {
    const getBalance = response.data;
    return getBalance;
}

Send Transaction

Send a certain amount (in ethers) to a certain address. Returns the transaction object.

Please note that since Plurality profiles are chain agnostic, you need to provide the RPC and the chainId to ensure that balance is being read from the current read. You can find the RPC and the chainId of your preferred chain through this link. We currently only support EVM-compatible chains.

const response = (await PluralitySocialConnect.sendTransaction(rawTx, rpc, chainId)) as SendTransactionDataType;
if (response) {
    const sendTransactionData = response.data;
    return sendTransactionData;
}

Get Block Number

Returns the latest block number.

const response = (await PluralitySocialConnect.getBlockNumber(rpc, chainId)) as GetBlockNumberDataType;
if (response) {
    const blockNumber = response.data;
    return blockNumber;
}

Get Transaction Count

Returns the transaction count of the given address

const response = (await PluralitySocialConnect.getTransactionCount(address, rpc, chainId)) as GetTransactionCountDataType;
if (response) {
    const transactionCount = response.data;
    return transactionCount;
}

Read from contract

Returns the response of executing the given get method of the contract with the given parameters

const response = (await PluralitySocialConnect.readFromContract(address, abiVal, action, params, rpc, chainId)) as ReadFromContractDataType;
if (response) {
    const readContract = response.data;
    return readContract;
}

Write to contract

Returns the transaction response of executing the given write method of the contract with the given parameters

const response = (await PluralitySocialConnect.writeToContract(address, abiVal, action, params, rpc, chainId, options)) as WriteToContractDataType;
if (response) {
    const writeContract = response.data;
    return writeContract;
}

Didn't find what you were looking for? Contact us on discord here.

Last updated