Skip to content

General Questions about the JS SDK #32

Answered by BenKurrek
BenKurrek asked this question in Q&A
Discussion options

You must be logged in to vote

From @ailisp:

In response to "how do I pass in values into a function? and also the error about passing value to constructor":
You need to pass argument as array:

near call $JSVM_ACCOUNT call_js_contract --accountId $JSPROJ --args $(node encode_call.js $JSPROJ init '[10]') --base64 --amount 1

If there were more than one arguments, for example: (totalSupply, name) , pass it as: [10, "alice"]

In response to "how come my getTotal()function runs through the constructor everytime it’s called?":

Your observation is right. This is an intentional designed code generation to adapt JS's OOP model to NEAR's contract function call lifecycle. And it's the same design as near-sdk-rs's near_bindgen macro.

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by BenKurrek
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants