Connect to crypto wallet
const options = { method: 'GET', headers: { 'Accept': 'application/json', 'X-API-Key': 'KmzO1bg18y9d7kbaVia8tmzEWAcbnUDdX7PiPxuxapMwOVKfZ93TGaKcOmjQFs57' }, }; fetch('https://deep-index.moralis.io/api/v2/block/1000?chain=eth', options) .then((response) => response.json()) .then((response) => printResult(response)) .catch((err) => console.error(err)) const printResult = (response) => { const container = document.getElementById('result') container.innerHTML = "
" + JSON.stringify(response ,null, 2) + "
" }

Moralis API Response:

import axios from "axios"; import "./App.css"; import { useState } from "react"; import moralis from "./moralis.png"; function App() { const [address, setAddress] = useState(""); const [chain, setChain] = useState("0x1"); const [toBlock, setToBlock] = useState(""); const [balance, setBalance] = useState(null) async function fetchBalance() { let res; if(toBlock){ res = await axios.get(`http://localhost:3000/balance`, { params: { address: address, chain: chain, toBlock: toBlock }, }); }else{ res = await axios.get(`http://localhost:3000/balance`, { params: { address: address, chain: chain }, }); } console.log(res); setBalance((res.data.result.balance / 1E18).toFixed(2)) } function addressChange(e) { setAddress(e.target.value); setBalance(null); } function chainChange(e) { setChain(e.target.value); setBalance(null); } function blockChange(e) { setToBlock(e.target.value); setBalance(null); } return ( <> moralis
Get Wallet Native Balance
Wallet:
addressChange(e)} >
To Block:
blockChange(e)} >
Chain:
{balance &&
{balance}
}
); } export default App;