Replies: 4 comments 3 replies
-
For the |
Beta Was this translation helpful? Give feedback.
-
@gagdiez It will not satisfy this restriction: "We can not use near.signerAccountId() and other APIs in the constructor if it can be called from the “view” function" Also, view calls never write to the state, it requires signing, gas, etc. |
Beta Was this translation helpful? Give feedback.
-
Agreed with @gagdiez to try to call the default function in view instead of throwing an error. |
Beta Was this translation helpful? Give feedback.
-
I think @volovyks proposed workflow is quite solid. Take Counter contract, with default
The only thing doesn't work great is view before init points by @gagdiez , and Serhii also agreed. Seems the challenge here is user can use |
Beta Was this translation helpful? Give feedback.
-
Problems we are trying to solve:
init()
function is generated for the user. It looks too magical.default()
function in every contractinit()
function can be called several times (we need to add #[init] analog from Rust) that would prevent thisinit()
function after deployment. (handled by Default and PanicOnDefault in Rust SDK)Let's not forget to do things JS (OOP) way:
constructor()
Known restrictions:
near.signerAccountId()
and other APIs in the constructor if it can be called from the “view” functionDesign proposal:
call
function in case STATE does not existcall
andview
functions will throw errors (as an alternative,view
function can return null)These principles create 3 possible life cycles:
view
,call
, andinit
:In order to implement this design, we will need to:
init()
autogenerationconstructor
as a function that can be called externally (by user or developer)default()
function, which will always try to create an object using contractor without parameters. Example:Known limitations:
cc @ailisp @gagdiez @austinabell @BenKurrek @MaximusHaximus
Beta Was this translation helpful? Give feedback.
All reactions