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
Instead of this:
await cntchk.methods.checkContract(address).send({
from: accounts[0]
});
try this:
const res = await cntchk.methods.checkContract.call(address)