From 4cc977f803be2a3a1aa269fab90fd2ea3a0bad5e Mon Sep 17 00:00:00 2001 From: Yashovardhan Agrawal <21066442+yashovardhan@users.noreply.github.com> Date: Wed, 21 Aug 2024 12:23:37 +0530 Subject: [PATCH] nits --- .../src/app/web3RPC.ts | 16 +++--------- .../sfa-react-quick-start/src/web3RPC.ts | 26 ++++++++----------- .../sfa-vanillajs-quick-start/script.js | 15 +++++++---- 3 files changed, 25 insertions(+), 32 deletions(-) diff --git a/single-factor-auth-web/quick-starts/sfa-angular-quick-start/src/app/web3RPC.ts b/single-factor-auth-web/quick-starts/sfa-angular-quick-start/src/app/web3RPC.ts index 2db7a98d..6f43f612 100644 --- a/single-factor-auth-web/quick-starts/sfa-angular-quick-start/src/app/web3RPC.ts +++ b/single-factor-auth-web/quick-starts/sfa-angular-quick-start/src/app/web3RPC.ts @@ -73,22 +73,14 @@ const sendTransaction = async (provider: IProvider): Promise => { const web3 = new Web3(provider as any); // Get user's Ethereum public address - const address = (await web3.eth.getAccounts())[0]; - - // Get user's balance in ether - const balance = web3.utils.fromWei( - await web3.eth.getBalance(address), // Balance is in wei - "ether" - ); + const fromAddress = (await web3.eth.getAccounts())[0]; - if (balance === "0") { - throw new Error("Insufficient balance, please fund your account to use this"); - } + const destination = fromAddress; const amount = web3.utils.toWei("0.001", "ether"); // Convert 1 ether to wei let transaction = { - from: address, - to: address, + from: fromAddress, + to: destination, data: "0x", value: amount, }; diff --git a/single-factor-auth-web/quick-starts/sfa-react-quick-start/src/web3RPC.ts b/single-factor-auth-web/quick-starts/sfa-react-quick-start/src/web3RPC.ts index c1170237..6f43f612 100644 --- a/single-factor-auth-web/quick-starts/sfa-react-quick-start/src/web3RPC.ts +++ b/single-factor-auth-web/quick-starts/sfa-react-quick-start/src/web3RPC.ts @@ -1,7 +1,6 @@ import type { IProvider } from "@web3auth/base"; import Web3 from "web3"; - const getChainId = async (provider: IProvider): Promise => { try { const web3 = new Web3(provider); @@ -13,20 +12,20 @@ const getChainId = async (provider: IProvider): Promise => { } catch (error) { return error as string; } -} +}; const getAccounts = async (provider: IProvider): Promise => { try { const web3 = new Web3(provider as any); // Get user's Ethereum public address - const address = (await web3.eth.getAccounts()); + const address = await web3.eth.getAccounts(); return address; } catch (error) { return error; } -} +}; const getBalance = async (provider: IProvider): Promise => { try { @@ -45,7 +44,7 @@ const getBalance = async (provider: IProvider): Promise => { } catch (error) { return error as string; } -} +}; const signMessage = async (provider: IProvider): Promise => { try { @@ -67,7 +66,7 @@ const signMessage = async (provider: IProvider): Promise => { } catch (error) { return error as string; } -} +}; const sendTransaction = async (provider: IProvider): Promise => { try { @@ -84,7 +83,7 @@ const sendTransaction = async (provider: IProvider): Promise => { to: destination, data: "0x", value: amount, - } + }; // calculate gas transaction before sending transaction = { ...transaction, gas: await web3.eth.estimateGas(transaction) } as any; @@ -92,16 +91,13 @@ const sendTransaction = async (provider: IProvider): Promise => { // Submit transaction to the blockchain and wait for it to be mined const receipt = await web3.eth.sendTransaction(transaction); - return JSON.stringify(receipt, (key, value) => - typeof value === 'bigint' - ? value.toString() - : value // return everything else unchanged + return JSON.stringify( + receipt, + (key, value) => (typeof value === "bigint" ? value.toString() : value) // return everything else unchanged ); } catch (error) { return error as string; } -} - - +}; -export default {getChainId, getAccounts, getBalance, sendTransaction, signMessage}; \ No newline at end of file +export default { getChainId, getAccounts, getBalance, sendTransaction, signMessage }; diff --git a/single-factor-auth-web/quick-starts/sfa-vanillajs-quick-start/script.js b/single-factor-auth-web/quick-starts/sfa-vanillajs-quick-start/script.js index d615e4b7..70e13545 100644 --- a/single-factor-auth-web/quick-starts/sfa-vanillajs-quick-start/script.js +++ b/single-factor-auth-web/quick-starts/sfa-vanillajs-quick-start/script.js @@ -25,21 +25,26 @@ let web3auth = null; $(".btn-logged-in").hide(); $("#sign-tx").hide(); - // IMP START - SDK Initialization // IMP START - Dashboard Registration const clientId = "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ"; // get your clientId from https://dashboard.web3auth.io // IMP END - Dashboard Registration + // IMP START - Chain Config const chainConfig = { chainNamespace: "eip155", - chainId: "0x1", // Please use 0x1 for Mainnet - rpcTarget: "https://rpc.ankr.com/eth", - displayName: "Ethereum Mainnet", - blockExplorer: "https://etherscan.io/", + chainId: "0xaa36a7", + rpcTarget: "https://rpc.ankr.com/eth_sepolia", + // Avoid using public rpcTarget in production. + // Use services like Infura, Quicknode etc + displayName: "Ethereum Sepolia Testnet", + blockExplorerUrl: "https://sepolia.etherscan.io", ticker: "ETH", tickerName: "Ethereum", + logo: "https://cryptologos.cc/logos/ethereum-eth-logo.png", }; + // IMP END - Chain Config + // IMP START - SDK Initialization const ethereumPrivateKeyProvider = new window.EthereumProvider.EthereumPrivateKeyProvider({ config: { chainConfig }, });