Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues calling a contract #14

Closed
asbjornenge opened this issue Jan 30, 2019 · 14 comments
Closed

Issues calling a contract #14

asbjornenge opened this issue Jan 30, 2019 · 14 comments

Comments

@asbjornenge
Copy link

Hi there 😄

Thanks for a great lib 🎉 I'm just getting started with Tezos and was trying out you library following https://hackernoon.com/tezos-smart-contracts-with-reasonml-docker-and-a-sandboxed-node-89df929ca1cf

I wanted to call the contract from sotez but I keep getting TypeError: u is not a constructor.

I have been trying with the following:

const sotez = require('sotez');
const provider = "http://localhost:18731";

let keys = {
  pk: 'edp...',
  pkh: 'tz...',
  sk: 'edsk...'
} 

let payload = {
  to: 'KT1...',
  from : 'tz1...',
  keys,
  amount: 10,
  parameters: 'main 2',
}

sotez.node.setProvider(provider)

;

(async () => {
  try {
    let contract = await sotez.contract.load(payload.to) // works
    console.log(contract)
    let res = await sotez.contract.send(payload) // error
    console.log(res)
  } catch(e) {
    console.error(e)
    process.exit(1)
  }
})()

I'm probably using the params wrong of something. Any input? Is there some way I can use src/sotez.node for easier debugging? The compiled dist is of little help 😝

Calling the contract using liquidity cli works fine.

@AndrewKishino
Copy link
Owner

Liquidity uses a parameter syntax which can define entry points into different parts of a contract. I assume you are calling the main entry point for this contract which is the default. If you change your parameter to be:

{
  ...
  parameters: '2',
}

the constructed payload in the actual call gets formatted as { int: '2' }.

What I found really useful was using liquidity's online IDE with the developer tools network tab open and try forging operations and see how your parameters are being formatted in the forging calls.

@asbjornenge
Copy link
Author

Tried that too, but getting the same error 🤔 It seems to be related to the mutez parameter...? When I set that to true I get a different error. Here is the stack:

TypeError: u is not a constructor
    at Object.mutez (/srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:90246)
    at Object.transfer (/srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:103067)
    at Object.send (/srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:108366)
    at /srv/asbjornenge/tezos-environment-manager/examples/updateContract.js:26:36
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:182:7)

@AndrewKishino
Copy link
Owner

I was able to recreate the issue. Seems like it was caused by this issue MikeMcl/bignumber.js#217 from bignumber. Anyways, I pushed a fix and updated the version. Update your version to 0.2.6 and see if it is working for you.

@asbjornenge
Copy link
Author

@AndrewKishino thanks 😬

Well, atleast I get differet errors now 😝🙈

Calling with parameter: '2' i get:

TypeError: parseInt(...).toString(...).padStart(...).join is not a function
    at /srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:106360
    at Array.map (<anonymous>)
    at A (/srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:106267)
    at Object._.encodeRawBytes (/srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:106605)
    at Object.parameters (/srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:100942)
    at Object.op (/srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:102673)
    at /srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:103598
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:103573)
    at y (/srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:85219)

Calling with parameter: { int: '2' } I get:

TypeError: e.replace is not a function
    at Object.A (/srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:90525)
    at Object.m.transfer (/srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:112402)
    at Object.send (/srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:117859)
    at /srv/asbjornenge/tezos-environment-manager/examples/updateContract.js:26:36
    at Object.<anonymous> (/srv/asbjornenge/tezos-environment-manager/examples/updateContract.js:33:3)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)

Full payload:

let payload = {
  to: 'KT1...',
  from : 'tz1...',
  keys,
  amount: 1,
  parameter: { int: '2' }
}

🤷‍♂️

@AndrewKishino
Copy link
Owner

@asbjornenge Looks like I may have introduced a small bug when forging ints. New version should be up. Go ahead and give it a try. Thanks for being so patient!

@asbjornenge
Copy link
Author

@AndrewKishino nono, thank YOU for creating this module and helping out 😬👍

Got further this time, but got stuck on signing;

TypeError: invalid privateKey length
    at E (/srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:7:50002)
    at Object.VA [as crypto_sign_detached] (/srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:7:86566)
    at Object.sign (/srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:94160)
    at /srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:110484
    at y (/srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:85219)
    at Generator._invoke (/srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:85007)
    at Generator.A.(anonymous function) [as next] (/srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:85398)
    at i (/srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:87952)
    at a (/srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:88154)
    at /srv/asbjornenge/tezos-environment-manager/examples/node_modules/sotez/dist/sotez.node.js:1:88213

I forked the module and messed about a bit 😝 Had some issues with babel and the tests, so I made a commit that fixes it for me. You can take a peak here asbjornenge@f5c0270 - I'll be happy to PR this if you want it.

But, once the tests were up and running I managed to reproduce the error by uncommenting the sign test and passing a tezos sk to the crypto.sign function. Hope that helps with debugging 👍

@AndrewKishino
Copy link
Owner

So this error is valid, however the current implementation only supports secret keys which are generated through sotez, or ledger hardware wallets. If you generate a new address using sotez and use that as your keys, that should resolve this latest issue you are seeing.

@AndrewKishino
Copy link
Owner

@asbjornenge I pushed a change that should detect which sk format you are using and extracts the sk format you can use to sign messages. Hopefully this helps! 🙏

@asbjornenge
Copy link
Author

asbjornenge commented Feb 1, 2019

Fantastic 🎉 I can now sign 🚀 I was using the keys from one of the accounts created on my node during the tutorial. They have xtz already so thought it was a good idea 😝 Thanks a bunch for all your help!

I still get an error:

[{"kind":"generic","error":"Operation ooyZrcyeBjYFkC8Yr9t5VwDSn4HvUVWu5gsLQHW3QdEHppYonbo rejected by the mempool pre filter"}]

Any idea what this means? Probably something to do with my node or the params I'm sending...? 🤔

@AndrewKishino
Copy link
Owner

You may need to set a higher fee.

@asbjornenge
Copy link
Author

Tried setting the fee: 1 which is what I did with liquidity-cli but still same issue 🤔 Getting an error if I try to set it to 0.5.

Failed to parse the request body: No case matched:
  At /kind, unexpected string instead of endorsement
  At /kind, unexpected string instead of seed_nonce_revelation
  At /kind, unexpected string instead of double_endorsement_evidence
  At /kind, unexpected string instead of double_baking_evidence
  At /kind, unexpected string instead of activate_account
  At /kind, unexpected string instead of proposals
  At /kind, unexpected string instead of ballot
  At /kind, unexpected string instead of reveal
  Unhandled error (Invalid_argument "Z.of_substring_base: invalid digit")
  At /kind, unexpected string instead of origination
  At /kind, unexpected string instead of delegation

@AndrewKishino
Copy link
Owner

The fee is expressed as mutez (1/1,000,000 of a tez) the default fee for transfers is set to 1278 so for a contract you may need to set it a bit higher due to the computations of the contract. If you're in a test environment, I would just start playing with the fee values and possibly the gasLimit and storageLimit values to find what works best for your use case.

@asbjornenge
Copy link
Author

@AndrewKishino aha! That worked 😬🎉 I was fiddling with those other params too, but kept the fee too low.

The docs says 0.05 is the default 🤷‍♂️🙈

Again, thanks for all your help with this issue! I'm going to continue exploring Tezos and this lib 😉👍

@AndrewKishino
Copy link
Owner

Will update the docs to reflect the correct fees. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants