Calling function in truffle console error

0 votes

How do I correctly call a function of a contract that in the truffle console?

Using the petshop example project, I migrated the contract onto the network successfully.

In the truffle console I executed:

var ad = Adoption.deployed()

This yields the reply:

undefined

When I execute ad.adopt(23); adopt being the function name and 23 being the unit parameter; I get the exception TypeError: ad.getAdopters is not a function

How to solve this error?

Oct 10, 2018 in Blockchain by digger
• 26,740 points
2,891 views

1 answer to this question.

0 votes

Inside Truffle console

ContractName.deployed().then(function(instance){app = instance})
app.adopt(23)//call method on contract class

Try this inside your app.

//from App.js
App.contracts.SmartContractName.deployed().then(function(instance){
   return instance.adopt(23)//call method on contract class
}).then(function(){

}).catch(function(err){
   console.log(err);
})
answered Oct 10, 2018 by Omkar
• 69,220 points

just remove "var" and do the following:

ad = Adoption.deployed()

Related Questions In Blockchain

0 votes
1 answer

Can't call contract function in truffle console

Inspect the object adoption within the console. You will ...READ MORE

answered Sep 28, 2018 in Blockchain by slayer
• 29,370 points
3,108 views
+1 vote
5 answers

How to solve "truffle: command not found" error in blockchain?

First try restarting the system and then ...READ MORE

answered Jul 16, 2018 in Blockchain by slayer
• 29,370 points
12,015 views
0 votes
1 answer

Truffle migrate fails due to missing function, but it exists in node_modules

deployer.deploy(password1, password2, deadline, {value: 100, from: accounts[0]}); ...READ MORE

answered Oct 3, 2018 in Blockchain by digger
• 26,740 points
2,026 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,947 views
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 69,220 points
1,488 views
0 votes
2 answers

Why is network already up to date while trying to deploy a contract on truffle?

I guess you have ganache running already ...READ MORE

answered Apr 24, 2018 in Blockchain by Shashank
• 10,400 points
4,596 views
0 votes
1 answer

How can I deploy a HelloWorld contract on my testrpc network?

The problem lies in the command: truffle migrate Your truffle migrate command ...READ MORE

answered Apr 27, 2018 in Blockchain by Perry
• 17,100 points

edited Aug 10, 2018 by Omkar 2,888 views
0 votes
1 answer

truffle compile shows error: TypeError: Invalid type for argument in function call.

You are getting this error because you ...READ MORE

answered Dec 5, 2018 in Blockchain by Omkar
• 69,220 points
2,248 views
0 votes
1 answer

Not able to migrate contract in Truffle: Error: No network specified. Cannot determine current network

Make these entries in truffle.js file: module.exports = { ...READ MORE

answered Nov 30, 2018 in Blockchain by Omkar
• 69,220 points
1,213 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP