near-api-js icon indicating copy to clipboard operation
near-api-js copied to clipboard

Near api call contract missing type enforcement

Open cold-briu opened this issue 1 year ago • 0 comments

Prerequisites

  • [X] I'm using the latest version of near-api-js.
  • [ ] I have tried to start with a fresh project and reproduce the defect with minimal code changes.
  • [ ] I have read the console error messages carefully (if applicable).

Description

Take this snippet as an example https://docs.near.org/tools/near-api-js/contract#call-contract

In this example, the attached amount should be a string, however, if I send a number instead (by using a parseInt) the explorer will tell that attached amount is zero.

I would expect that near-api-js tells me something like

method_name attachedDeposit type error expecting string

Reproducible demo

No response

Steps to reproduce

Run this snippet https://docs.near.org/tools/near-api-js/contract#call-contract

await contract.method_name(
  {
    arg_name: "value", // argument name and value - pass empty object if no args required
  },
  "300000000000000", // attached GAS (optional)
  parseInt("1000000000000000000000000") // attached deposit in yoctoNEAR (optional)
);

Expected behavior

Error: method_name attachedDeposit type error expecting string

Actual behavior

Transaction runs a successfultx but the explorer shows attached amount as zero.

Your environment

  • NEAR JavaScript API version used: 1.0
  • Frontend framework (if applicable):
  • Relevant dependencies (if applicable):

Self-service

  • [ ] I'd be willing to fix this bug myself.

cold-briu avatar Oct 13 '23 08:10 cold-briu