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

63
Views
My smart contract functions show up as undefined when I try to call them using JavaScript

To start off, I'm fairly new to JavaScript and web3, so please excuse me if the question's very trivial.

if (typeof web3 !== 'undefined') {
   web3Provider = web3.currentProvider;

   web3 = new Web3(web3.currentProvider);
 } else {
   web3Provider = new Web3.providers.HttpProvider('http://localhost:7545');
   web3 = new Web3(App.web3Provider);
 }

This is the way I currently instantiate web3, not sure if it's deprecated (I feel like this could potentially be the problem)

When I attempt to log the getAccounts() function like this

console.log(web3.eth.getAccounts())

I'm faced with:

web3.min.js:2 Uncaught (in promise) TypeError: e is not a function
at web3.min.js:2
at web3.min.js:2
at r (inpage.js:1)
at s._handle (inpage.js:17)

and also when I attempt to call my solidity functions, namely one named "addFood()" that takes in 4 parameters like this,

var eth_pk = document.getElementById("pk").value
   console.log(eth_pk)    //console.log logs the output values in the javascript console.
   var eth_fd = document.getElementById("fd").value
   console.log(eth_fd)
   var eth_pl = document.getElementById("pl").value
   console.log(eth_pl)
   var eth_prc = document.getElementById("prc").value
   console.log(eth_prc)
   contract.methods.addFood(eth_pk, eth_fd, eth_pl, eth_prc).send({ from: web3.eth.defaultAccount }, function(error, result)
 {
   console.log(result)
 })

I'm faced with

Uncaught TypeError: Cannot read properties of undefined (reading 'addFood')
at HTMLFormElement.<anonymous> (sell.html:208)

I'll provide any additional code that's needed to solve this issue. I'd be very grateful if someone could solve this! Thank you!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You're probably using MetaMask, in which case your provider is window.ethereum

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!