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

117
Views
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 answers
Answer question

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 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!