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

257
Views
How to call external function in chain function?

This is a case about React and Dapp.

I call web3j to sendTransaction and wait callback by chian fucntion. While error occur , I can't call the function inside App.

I descibe the situations below codes around error block.

Is it possible to call function 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..");
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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>
  );
}
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!