SDK Methods for <v0.1.13

Compatible Networks

  • Ethereum Goerli

  • Polygon Mumbai

Instance creation and imports

Developers can directly get access to Banana module through our SDK just by importing the banana module from banana-wallet-sdk

import { Banana } from '@rize-labs/banana-wallet-sdk/dist/BananaProvider'

Once you successfully imported Banana Module, you can start accessing the methods it exposes just by creating an instance of it by specifying the appropriate chain. Currently, we are on Georli Testnet and polygon Mumbai.

You can create a banana Instance as:

// importing chains and banana module from banana wallet sdk
import { Banana } from '@rize-labs/banana-wallet-sdk/dist/BananaProvider'
import { Chains } from '@rize-labs/banana-wallet-sdk/dist/Constants' 

const jsonRpcProviderUrl = 'your-rpc-url';

// creating chain specific instance of banana module
const bananaInstance = new Banana(Chains.goerli, jsonRpcProviderUrl)

Methods by Banana Module

Once the instance is ready, developers can access multiple methods the banana module provides.

Methods offered by the banana module are:

  • getWalletName

  • isWalletNameUnique

  • getWalletAddress

  • getAAProvider

  • execute

getWalletName

getWalletName the method enables developers to read user cookies and get the wallet name saved into the cookie for display purposes and get a smart contract wallet address. If this method doesn't return anything, then it surely means the user might have cleared the cookies. In this case, the developers should manually prompt the user for the wallet name.

Usage

/*
 * @params none
 * @returns wallet name: string
 * accessed from the banana instance and be used to fetch wallet name.
 * cached in the user's cookie storage 
 */
const walletName: string = bananaInstance.getWalletName();

isWalletNameUnique

isWalletNameUnique the method enables developers to check whether the wallet name their user suggests is unique. We had kept the wallet name as the primary key in the wallet credentials database on our server. (Suggestion: users can keep their Gmail account username as their wallet name as it's always unique).

Usage

// fetching wallet name for the user
const walletName: string = "walletname";

/*
 * @params walletName: string
 * @returns isUnique: bool
 * @nature async
 * accessed form banana instance and be used to check if walletName is unique
 */
const isUnqiue: boolean = await bananaInstance.isWalletNameUnique(walletName);

getWalletAddress

getWalletAddress is one of the most critical methods for our banana SDK as it enables developers to fetch the smart contract wallet Address for their user additionally it setups multiple entities at the SDK core.

It handles two cases.

  • The user has already created a wallet.

    • In this case, our SDK will fetch the wallet address of the deployed smart contract wallet from the passed wallet name.

  • The user hasn't created any wallet.

    • In this case, our SDK will initialize a smart contract wallet for the user and will require biometric / passcode-based authentication for the process. Once initialization completes, it will return the deterministic smart contract wallet address, which users can further fund and start making transactions.

Usage

// fetching wallet name for user
const walletName: string = bananaInstance.getWalletName();

/*
 * @params walletName: string
 * @returns Smart Contract Wallet Address: string
 * @nature async 
 */
const walletAddress: string = await bananaInstance.getWalletAddress(walletName);

getAAProvider

getAAProvider enables developers to get ERC 4337-based providers for their smart contract wallet, which developers can use in multiple ways. This includes signing transactions (Work in progress), creating contract instances with signers, etc.

Usage

// fetching wallet name for user
const walletName: string = bananaInstance.getWalletName();

// getting smart contract wallet address
const walletAddress: string = await bananaInstance.getWalletAddress(walletName)

/*
 * @params walletAddress: string
 * @returns provider: ERC4337Provider
 * @nature async 
 */
const aaProvider = await bananaInstance.getAAProvider(walletAddress);

signMessage

Developers can utilize signMessage method of bananaInstance to enable users to sign messages using their wallet. While signing, The message passed will be hashed and then signed by the wallet.

Usage

/*
 * @params message: string
 * @returns object { process: boolean, signature: string, signedMessage: string }
 * process: indicates whether message is signed successfully or not
 * signature: Signature retrieved after signing message.
 * signedMessage: Message which is signed.
 * @nature async 
 */
const sampleMsg = "Hello World";
const signedMessage = await bananaInstance.signMessage(sampleMsg);

execute

Developers can utilize the execute method of banana to execute a transaction via users' smart contract wallet. To use this method, developers must pass on callData a function (call data of function which user wants to call), destination address (contract address whose function is getting called), and value (in case of payable function is called).

For now, we are supporting single transaction execution bundling is under development.

Please don't use this method for view function calls. For just to read any contract data you can directly call it from your contract instance.

Usage

// fetching wallet name for user
const walletName: string = bananaInstance.getWalletName();

// getting smart contract wallet address
const walletAddress: string = await bananaInstance.getWalletAddress(walletName)

const aaProvider = await bananaInstance.getAAProvider(walletAddress);

// extracting aaSigner
const aaSigner = aaProvider.getSigner();

// initializing sample greeter contract with aaSigner
const GreeterContract = new ethers.Contract(
     addresses.Greeter,
     GreeterArtifact.abi,
     aaSigner
    );

// greeter contract greet calldata
const greetCallData = GreeterContract.interface.encodeFunctionData(
      "greet",
       []
    );

/*
 * @params functionCalldata: bytes, walletAddress: string, address: string, value: double
 * @return transaction hash
 * @nature async
 */
const txn = await bananaInstance.execute(greetCallData, Greeter.address, amount)


// example for view call 
const greetings = await GreeterContract.getGreeting();

PS: if after following this documentation you are experiencing webpack polyfill issue please refer to this page

If you have any questions please post them Banana SDK Discord forum.

Last updated