current position:Home>web3. JS call problem
web3. JS call problem
2022-02-03 23:28:33 【Q & A of Denglian community】
I'm learning web3.js, Want to use html Display the balance of the query address , When you click the button , Find out js You can view the balance , But it cannot be assigned to html The elements of , How can I change it ?
<!DOCTYPE html><html> <head> <script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/web3/1.3.0/web3.min.js"></script> <title>view your balance</title> <style> input[type=text], select { width: 100%; padding: 12px 20px; margin: 8px 0; display: inline-block; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; } button[type=button] { width: 100%; background-color: #4CAF50; color: white; padding: 14px 20px; margin: 8px 0; border: none; border-radius: 4px; cursor: pointer; } div { width: 300px; border-radius: 5px; background-color: #f2f2f2; } </style> <script> </script> </head> <body> <h3> Check your wallet balance </h3> <div> <form> <label for="title">My Balance</label> <input type="text" id="address" name="address" placeholder="Your address.."> <button id="getBalance" type="button" onclick="myBalance()">getBalance</button> <h3 id="thebalance">0</h3> </form> </div> <script> function myBalance(){ var infuraUrl = "https://kovan.infura.io/v3/6185543f1415428fb08d15c08ec22c2c" var privateKey = "03c6cd272dd6e913ca6bd9501f37dac27f4deb0262711d9af589beb15a1c0c8a" var web3 = new Web3(infuraUrl) var account = web3.eth.accounts.privateKeyToAccount(privateKey) web3.eth.defaultChain = 'Kovan' var fromAddr = account.address var fromAddr1 = document.getElementById("address").value; web3.eth.getBalance(fromAddr1).then(console.log) web3.eth.getBalance("fromAddr1").then(function(balance){document.getElementById("thebalance").innerHTML = balance;}); } </script> </body></html>
Other answers 1:
copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/02/202202032328314042.html
The sidebar is recommended
- What is the current circulation of link?
- Excuse me, Web3 JS how to call approve authorization, can you give an example code? thank you
- When verifying the smart contract in Etherscan, the ABI error is always prompted
- Ethereum contract cannot be called
- How to modify the issuance of Ethereum tokens
- How to set the asset withdrawal function of token publishing contract address?
- On the problem of geth connection cluster
- Can a blockchain generate blocks in milliseconds?
- How to obtain the signature when an external contract calls this contract?
- Why use call? Can't you directly use the method to import the interface of the contract
guess what you like
-
How to use other addresses to transfer eth out of the contract
-
Through abi Can't a query method be called by encoding be defined as view
-
There are some tokens in the contract. Can you approve the tokens in the contract to a certain address
-
How does Web3 get nonce including padding status
-
How to connect the front end to the Ethereum Wallet
-
web3. JS calling contract method reports an error VM exception while processing transaction: revert
-
Why does if (1 = = 1) {XXX} affect the execution of XXX code?
-
There was a problem issuing the uniswap contract
-
How to determine the order of transactions with the same gas price in the same block
-
How to use the call, callcode, and delegatecall functions called by the solidity contract?
Random recommended
- Remix compilation error
- How to get the gas price of pending transaction?
- Etherscan website cannot be accessed
- The code is picked up on the Internet. When it is written after Remix deployment, it is' gas estimation failed, gas required exceeds allowance (8000000) or always failing transaction
- Error in solidity: typeerror: data location must be 'memory' for return
- Full path returned from traversal of solidness multitree
- Remix deployment contracts have been pending
- How can you always prompt timeout when developing deployment contracts with truss
- When compiling, truss prompts that the version of solidity is wrong, but the version required by the contract has been set in truss config. What should I do
- Is there a decentralized shopping contract
- BTC account balance query
- Truffle migrate deploys a contract,
- When using truss run verify to verify Etherscan code, errors are always reported
- Generally, there are many transactions in eth's pending pool. After all, there are at most 200 transactions per block
- DAPP page monitoring network
- How does solidity call the global variables of other contracts?
- Super ledger expansion
- On the mapping of proficient in Ethereum smart contract development course.
- Verification and transfer of Ethereum balance and token balance
- How does solidity realize large number operation
- How does library query block information
- How does Ethereum change the consensus mechanism
- The difference between memory and storage temporary variables set in solidity
- Problems of Web3 interaction
- How does truss deploy multi file contracts and merge contract files
- Fail with error 'TransferHelper: TRANSFER_ FROM_ FAILED'
- Can one method in solidity call two methods of transferring tokens
- Ethereum node server
- Course blockchain full stack development - Web3 cannot be imported in the actual practice of Ethereum DAPP development
- Xiaobai learns the development process of Ethereum smart contract DAPP
- The shared folder with Remix ide enabled locally cannot be connected
- A timeout pops up at the end of deploying the contract with truss, but there is already a contract on the chain when looking at the chain. Is the contract complete in this case?
- Will the use of nest Oracle for stable currency exchange have advantages over curve and centralized exchange exchange exchange?
- Smart contract operation offline program
- The DAPP browser integrated environment of wallet is insufficient
- Is there ide code completion and error prompt comparable to remix
- How does Bellman optimize the performance of proof
- Web3 calls the smart contract method. Can you call multiple contract methods at one time? Either they all succeed or they all fail
- Please ask a question about Ethereum chain configuration change
- Decompiled smart contracts are not understood