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 24 in Blockchain by Vaishnavi
98 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 24 by Omkar
• 67,480 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,050 points
198 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,050 points
175 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,050 points
28 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,050 points
40 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
141 views
0 votes
1 answer
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
• 67,480 points
77 views
0 votes
1 answer
0 votes
2 answers
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,050 points
306 views