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

127
Views
¿Cómo muestro una salida booleana de mi función de solidez y la uso en un javascript?

Estoy tratando de hacer un contrato que muestre si una dirección determinada es un contrato o simplemente una dirección. El código de solidez es así.

solidez de pragma ^0.8.0;

contrato esContrato{

 function checkContract(address addr) public view returns (bool answer) { bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; bytes32 codehash; assembly { codehash := extcodehash(addr) } return (codehash != 0x0 && codehash != accountHash); }

}

incluso traté de darle al bool una variable y llamarlo en el javascript pero no funciona, el error mostró que la respuesta no está definida

 import './App.css'; import React from 'react'; import web3 from './web3'; import cntchk from './cntchk'; class App extends React.Component { state = { value: '', message: '' }; onSubmit = async (event) => { event.preventDefault(); const accounts = await web3.eth.getAccounts(); const address = this.state.value; this.setState({ message: 'checking to see if the address is contract or not' }); await cntchk.methods.checkContract(address).send({ from: accounts[0] }); this.setState({ message: 'the given address is..',answer }); }; render() { return ( <div> <h2>lottery contract</h2> <p>This contract is managed by there are currently {this.state.players} people entered. competing to win ether ! </p> <hr /> <form onSubmit={this.onSubmit}> <h4>want to </h4> <div> <label>amount of ether to enter</label> <input value={this.state.value} onChange={event => this.setState({value: event.target.value})} /> </div> <button>enter</button> </form> </div> ); } } export default App;
 <script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

donde cntchk es el javascript que contiene el abi y la dirección

todo lo que quiero es tomar la dirección como entrada y devolver si es un contrato o no a través de boolean. por favor ayuda

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

En lugar de esto:

 await cntchk.methods.checkContract(address).send({ from: accounts[0] });

prueba esto:

 const res = await cntchk.methods.checkContract.call(address)
about 4 years ago · Juan Pablo Isaza Report
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!