diff --git a/dapps/react-dapp-v2-with-ethers/src/App.tsx b/dapps/react-dapp-v2-with-ethers/src/App.tsx index b7bb64e..637a2b4 100644 --- a/dapps/react-dapp-v2-with-ethers/src/App.tsx +++ b/dapps/react-dapp-v2-with-ethers/src/App.tsx @@ -27,7 +27,7 @@ import { SToggleContainer, } from "./components/app"; import { useWalletConnectClient } from "./contexts/ClientContext"; -import { utils } from "ethers"; +import { BigNumber, utils } from "ethers"; interface IFormattedRpcResponse { method: string; @@ -89,6 +89,36 @@ export default function App() { await ping(); }; + const testSendTransaction: () => Promise = async () => { + if (!web3Provider) { + throw new Error("web3Provider not connected"); + } + + const { chainId } = await web3Provider.getNetwork(); + const [address] = await web3Provider.listAccounts(); + const balance = await web3Provider.getBalance(address); + + const tx = await formatTestTransaction("eip155:" + chainId + ":" + address); + + if (balance.lt(BigNumber.from(tx.gasPrice).mul(tx.gasLimit))) { + return { + method: "eth_sendTransaction", + address, + valid: false, + result: "Insufficient funds for intrinsic transaction cost", + }; + } + + const txHash = await web3Provider.send("eth_sendTransaction", [tx]); + + return { + method: "eth_sendTransaction", + address, + valid: true, + result: txHash, + }; + }; + const testSignTransaction: () => Promise = async () => { if (!web3Provider) { throw new Error("web3Provider not connected"); @@ -214,7 +244,7 @@ export default function App() { }; return [ - // { method: "eth_sendTransaction", callback: onSendTransaction }, + { method: "eth_sendTransaction", callback: wrapRpcRequest(testSendTransaction) }, { method: "eth_signTransaction", callback: wrapRpcRequest(testSignTransaction) }, { method: "personal_sign", callback: wrapRpcRequest(testSignMessage) }, { method: "eth_sign (standard)", callback: wrapRpcRequest(testEthSign) },