Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

118
Vistas
how do i show a boolean output from my solidity function and use on a javascript?

i am trying to make a contract that show if a given address is a contract or just an address the solidity code is like this.

pragma solidity ^0.8.0;

contract isItContract{

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

}

}

i even tried to give the bool a variable and call it in the javascript but it i not work the error showed answer not defined

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>

where cntchk is the javascript which contains the abi and address

all i want is to take address as an input and return if it is contract or not through boolean. pls help

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Instead of this:

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

try this:

const res = await cntchk.methods.checkContract.call(address)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda