Este es un caso sobre React y Dapp.
Llamo a web3j para enviar Transacción y espero la devolución de llamada por chian fucntion. Mientras ocurre un error, no puedo llamar a la función dentro de la aplicación.
Describo las situaciones debajo de los códigos alrededor del bloque de error.
¿Es posible llamar a la función handleError?
//My code class App extends Component { constructor(props) { super(props); this.state = { status: '' }; }; startTrade(){ web3.eth.sendTransaction({ from: "0x123....", to: "0x456....", value: web3.utils.toWei("2", "ether"), }).on('error', (error)=>{ //If write this line,the browser shows directly: //Failed to compile //src\App.js //Line 62:7: 'handleFail' is not defined no-undef //handleError(); //If add this. when error occurs,the console shows: //App.js:62 Uncaught TypeError: Cannot read properties of undefined (reading 'handleFail') //this.handleFail(); //If I call otherHandle,It's work. //However I don't have the instance of App to change something... //otherHandle(); }); } handleError(){ console.log("Do something.."); } render(){ return(); } } function otherHandle(){ console.log("Do something.."); }export default function App() { const handleError = (error) => { console.log("Do something..", error.message); } const startTrade = ()=>{ web3.eth.sendTransaction({ from: "0x0Cb......", to: "0x61d63........", value: web3.utils.toWei("2", "ether"), }).on('error', (error)=>{ handleError(error); }); } // useEffect Function... useEffect(() => { startTrade(); // eslint-disable-next-line }, []); return ( <div className="App"> </div> ); }