import React from'react'import ReactDOM from'react-dom'import*as fcl from"@blocto/fcl"import'./index.css'import App from'./App'import*as serviceWorker from'./serviceWorker'fcl.config({"accessNode.api":"https://rest-testnet.onflow.org"// connect to Flow testnet});ReactDOM.render( <React.StrictMode> <App /> </React.StrictMode>,document.getElementById('root'))// If you want your app to work offline and load faster, you can change// unregister() to register() below. Note this comes with some pitfalls.// Learn more about service workers: https://bit.ly/CRA-PWAserviceWorker.unregister()
When user clicks the button, runGetLatestBlock sends a request to get information for the latest block on Flow and display the result in <Code> block.
Step 3 - Connect to Blocto wallet
Now, let's add login functionality to your dApp.
Create src/Authenticate.js
Add the component to src/App.js
Add config for FCL in src/index.js so FCL knows which wallet to use
import React from'react'import ReactDOM from'react-dom'import*as fcl from"@blocto/fcl"import'./index.css'import App from'./App'import*as serviceWorker from'./serviceWorker'fcl.config({"accessNode.api":"https://rest-testnet.onflow.org",// connect to Flow testnet"discovery.wallet":`https://wallet-v2-dev.blocto.app/${YOUR_DAPP_ID}/flow/authn`// use Blocto testnet wallet});ReactDOM.render( <React.StrictMode> <App /> </React.StrictMode>,document.getElementById('root'))// If you want your app to work offline and load faster, you can change// unregister() to register() below. Note this comes with some pitfalls.// Learn more about service workers: https://bit.ly/CRA-PWAserviceWorker.unregister()
When user clicks the login button, FCL calls out to Blocto wallet and the user can either register a new Blocto account or login to their existing Blocto accounts. Once the login process completes and user chooses to use the Blocto account on the dApp, the dApp gets the connected account information and show it in <UserProfile>.
Step 4 - Send a simple transaction
Finally, we can use the connected Blocto Flow account to send a transaction.
When user clicks the send button, FCL summons Blocto wallet and prompts user to either approve the transaction or reject it. If user approves of the transaction, Blocto wallet signs the message with the key in custodial and pass the signature back to FCL, where the transaction and the signature is sent to Flow network.
Awesome! You have sent a transaction to Flow testnet with Blocto wallet!