Calling Truffle Commands through a script

0 votes

I made the following contract:

pragma solidity ^0.4.17;

contract Checking {

    mapping( string => string ) PersonHash;

    function AddHash(string name, string hash) {

        PersonHash[name] = hash;

    }

    function GetHash (string name) public returns (string) {

        return PersonHash[name];

    }

}

Now I want to call this function from truffle using exec command.

I wrote a js file named checking.js with the following commands

var Checking = artifacts.require("./Checking.sol");

module.exports = function (deployer) {

  var ss;

  Checking.deployed().then(function(deployed){ ss=deployed; });

  ss.GetHash.call("sal");

}

I get an output error saying

Type Error: cannot read property 'GetHash' of undefined at .....
Jan 25, 2019 in Blockchain by Vaishnavi
1,249 views

1 answer to this question.

0 votes

Seems like its due to async behavior that is returned by Checking.deployed()

Change this:

var Checking = artifacts.require("./Checking.sol");

To this:

var Checking = artifacts.require("./Checking.sol").new();

 and then try.

answered Jan 25, 2019 by Omkar
• 69,220 points

Related Questions In Blockchain

0 votes
1 answer

Truffle tutorials "Error:recipient address is not a contract address"

It appears like you have already migrated ...READ MORE

answered Aug 8, 2018 in Blockchain by slayer
• 29,370 points
1,132 views
0 votes
1 answer

Invalid opcode error in a simple Solidity contract and script

You don't need to call .at() if you're using .new(). ...READ MORE

answered Sep 14, 2018 in Blockchain by slayer
• 29,370 points
4,819 views
0 votes
1 answer

Running blockchain script in a one liner

This is a direct translation of the ...READ MORE

answered Sep 18, 2018 in Blockchain by slayer
• 29,370 points
512 views
0 votes
1 answer

how loop through a JSON Array of bitcoin transaction data

for($i=0; $i<count($result['out']); $i++) { echo ...READ MORE

answered Sep 21, 2018 in Blockchain by slayer
• 29,370 points
738 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,923 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 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,464 views
0 votes
1 answer
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,566 views
0 votes
2 answers

How do I interact with a smart contract on a private network through web3.js

I found a blog that explains how ...READ MORE

answered Aug 20, 2018 in Blockchain by slayer
• 29,370 points
3,951 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