0

How can I send a uint parameter value to the contract in truffle?

i have a function that has two uint parameter and I wrote test that function but I guess the uint parameters cannt be sent as a correctly. Also I cannot see in mapping too the boolean value result of the uint parameter. (the HashList is mapping )

I'm putting log messages in truffle :


it('should be mint the token only owner', async()=>{
  const _hash = await actions.generateHash.call(50, '123');
  const inList = await actions.HashList(_hash);
  console.log('is there in list?    '+ inList);
  console.log('hash: '+_hash);
  console.log('all info: '+accounts[3], 50, '123', _hash);

  const res = await actions.create(accounts[3], 50, '123', _hash{from: accounts[0]});

  assert.isTrue(res, 'could not create. Please check contract or test code.' );

  });

My test outputs in here :

is there in list?false
hash: 38391047091755091013202618179480389830368877342597680687864504738175347992246
all info : 0x916666dBb04c97ea3D92647dF5b0De5Be5cD038B 50 123 BN {
  negative: 0,
  words: [
    51521206,       11804147,
    59004577,       116902,
    25125010,       60098687,
    16719740,       18977897,
    526954,         1390628,
    <1 empty item>
  ],
  length: 10,
  red: null
} BN {
  negative: 0,
  words: [
    51521206,       11804147,
    59004577,       116902,
    25125010,       60098687,
    16719740,       18977897,
    526954,         1390628,
    <1 empty item>
  ],
  length: 10,
  red: null
}

what is BN in all info output? why the Uint parameters shown as BN ?

thank you,

  • Your code doesn't match your output. How can _hash possible yield two different printouts??? – goodvibration Mar 29 at 9:27
  • More likely, that long printout is of res! – goodvibration Mar 29 at 9:27
  • the _hash result of the generateHash function. – sollover Mar 29 at 11:07
  • You have two console.log statements for _hash, and each one of them results with a different printout. Does that make any sense to you? – goodvibration Mar 29 at 11:18
  • @YaseminCırt Welcome to the Ethereum Stack Exchange! Please forgive goodvibration's gruffness, but it is good they have answered your question. I will try to clean up most of these comments. – eth Mar 29 at 15:22
0
  1. BN is a library for calculating with big numbers in JavaScript; see here for more details
  2. In order to print a complex object properly, use JSON.stringify on it; for example:

    Instead of console.log('all info: '+accounts[3], 50, '123', res);

    Do console.log('all info: '+accounts[3], 50, '123', JSON.stringify(res, null, 4));

| improve this answer | |
  • 1
    @YaseminCırt: 1. Please fix your question according to the comments. It's absolutely impossible for your _hash to just "change its value out of thin air". You're also missing a comma in _hash{from: accounts[0]}, and I'm guessing that there's a bunch of other basic coding errors. Don't post poorly-phrased questions and expect to get decent answers. 2. If you have a different question, then please post it separately. 3. If this answer has answered your question, then please accept it by clicking on the V next to it. Otherwise, please explain what part has not been answered. – goodvibration Mar 29 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.