// checking if wallet already existsconstname=awaitbananaInstance.getWalletName();let walletInstance, walletAddress;if (name) {// directly connecting wallet using the wallet name if wallet already exist walletInstance =awaitbananaInstance.connectWallet(name); walletAddress =awaitwalletInstance.getAddress();} else {// creating new wallet. walletInstance =awaitbananaInstance.createWallet(); walletAddress =awaitwalletInstance.getAddress();}
For making transactions from the wallet created we'll have to extract out signer from it and once signer is extracted we can use it's sendTransaction method to make transactions.
constsigner=awaitwalletInstance.getSigner();
Now let's create and send a transaction.
// sample abi for encoding transactionconstabi= [ { inputs: [], name:"returnStake", outputs: [], stateMutability:"nonpayable", type:"function", }, { inputs: [], name:"stake", outputs: [], stateMutability:"payable", type:"function", },];// extracting signer from the walletconstsigner=walletInstance.getSigner();// sample contract whose stake function we would invokeconststakeAddress="0x8b370128A84bc2Df7fF4813675e294b1ae816178";// creating transaction for the stake functionconsttx= { gasLimit:"0x55555", to: stakeAddress, value:ethers.utils.parseEther("100"), data:newethers.utils.Interface(abi).encodeFunctionData("stake", []),};// sending the transactionconsttxn=awaitsigner.sendTransaction(tx);