之前全是Algorithm1,添加下面就行
加入
\setcounter{algorithm}{2}
示例:
%FontSize=11
%TeXFontSize=11
\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{nopageno} % Do not display page numbers
\usepackage[utf8]{inputenc} % Ensure proper UTF-8 encoding
\setcounter{algorithm}{2}
\begin{document}
\begin{algorithm}
\caption{Connect Wallet and Send Data to Blockchain}
\begin{algorithmic}[1]
\STATE \textbf{Function} init()
\STATE \quad \textbf{If} Metamask is installed:
\STATE \quad \quad Use the existing provider: \texttt{web3 = new Web3(web3.currentProvider)}
\STATE \quad \textbf{Else}:
\STATE \quad \quad Alert user to install Metamask: \texttt{alert('Please install and log in to Metamask')}
\STATE \quad \quad \textbf{Return}
\STATE \quad Add event listener for "Connect Wallet" button:
\STATE \quad \quad \texttt{connectWalletBtn.addEventListener('click', connectWallet)}
\STATE \quad Add event listener for "Send Data" button:
\STATE \quad \quad \texttt{sendTransactionBtn.addEventListener('click', sendTransaction)}
\STATE \textbf{Function} connectWallet()
\STATE \quad \textbf{Try}:
\STATE \quad \quad Request wallet connection: \texttt{await ethereum.request(\{ method: 'eth\_requestAccounts' \})}
\STATE \quad \quad Log success: \texttt{console.log('Wallet connected')}
\STATE \quad \textbf{Catch error}:
\STATE \quad \quad Log error: \texttt{console.error('Error connecting wallet:', error)}
\STATE \textbf{Function} sendTransaction()
\STATE \quad Get the data from user input: \texttt{inputData = document.getElementById('inputData').value}
\STATE \quad \textbf{Try}:
\STATE \quad \quad Get the currently connected accounts: \texttt{accounts = await ethereum.request(\{ method: 'eth\_accounts' \})}
\STATE \quad \quad Use the first account: \texttt{from = accounts[0]}
\STATE \quad \quad Build the transaction object:
\STATE \quad \quad \quad \texttt{txObject = \{ from: from, to: '0x0000000000000000000000000000000000000000',}
\STATE \quad \quad \quad \texttt{value: 0, data: web3.utils.asciiToHex(inputData) \}}
\STATE \quad \quad Send the transaction: \texttt{txHash = await ethereum.request(\{ method: 'eth\_sendTransaction', params: [txObject] \})}
\STATE \quad \quad Log the transaction hash: \texttt{console.log('Transaction hash:', txHash)}
\STATE \quad \textbf{Catch error}:
\STATE \quad \quad Log error: \texttt{console.error('Error sending transaction:', error)}
\STATE \textbf{On Window Load}:
\STATE \quad Call \textbf{init} function to initialize the application: \texttt{window.addEventListener('load', init)}
\end{algorithmic}
\end{algorithm}
\end{document}