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:


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,720 points

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
   return instance.adopt(23)//call method on contract class

answered Oct 10, 2018 by Omkar
• 69,170 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,310 points
+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,310 points
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,720 points
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,830 points
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,170 points
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
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 1,471 views
0 votes
1 answer
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,170 points