Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
No se puede contratar con smartcontract con javascript para obtener la dirección de usuario y el saldo de smartcontract

Hola, soy nuevo en la tecnología blockchain. He creado un contrato inteligente que mostrará el saldo del contrato y los datos del usuario, como su dirección, saldo y el usuario puede depositar el monto insertado en el contrato inteligente. Mi código no funciona. No puedo mostrar ni el saldo del contrato ni los datos del usuario. funciona perfectamente en remix.

contrato inteligente

 // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.9.0; contract UserData { address owner; uint bal; constructor() { owner = msg.sender; } receive() external payable {} function getBalance() view public returns(uint) { return bal; } function deposit(uint amt) external payable { bal = bal + amt; bal += msg.value; } // function to get the useraddress function getOwner() public view returns (address) { return owner; } // Function to return current balance of user function getUserBalance() public view returns(uint256){ return owner.balance; } function withdraw(uint withdrawAmount) external payable { require(msg.sender == owner, "Only owner can withdraw!"); payable(msg.sender).transfer(withdrawAmount); } }

y aquí está mi código javascript:

 <script> var contract; $(document).ready(function(){ web3 = new Web3(web3.currentProvider); //ethereum.request({ method: 'eth_requestAccounts' }); var address = "0xd3553504e02681C4d4f1969017dAca11003bB496"; var abi = []; contract = new web3.eth.Contract(abi, address); contract.methods.getBalance().call().then(function(bal){ $('#balance').html(bal/10000000000000000); }) contract.methods.getOwner().call().then(function(address){ $('#userAddress').html(address); }) }) $('#deposit').click(function(){ var amt = 0; amt = parseInt($('#amount').val()); web3.eth.getAccounts().then(function(accounts){ var acc = accounts[0]; return contract.methods.deposit(amt).send({from: acc}); }).then(function(tx){ console.log(tx); }).catch(function(tx){ console.log(tx); }) }) </script>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!