Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda