【问题标题】:How to return a value from a call to a smart contract?如何从对智能合约的调用中返回一个值?
【发布时间】:2020-01-13 20:04:51
【问题描述】:

是否有任何示例可用于从修改链上存储的调用中返回值?

从读取中返回值当然不是问题,但有人提到从调用中获取返回也是可能的。

【问题讨论】:

    标签: nearprotocol


    【解决方案1】:

    我不确定你所说的获取返回值是什么意思,但这里有一个例子:

    export function incrementCounter(): i32 {
      let newCounter = storage.getPrimitive<i32>("counter", 0) + 1;
      storage.set<i32>("counter", newCounter);
      logging.log("Counter is now: " + newCounter.toString());
      return newCounter;
    }
    

    在前端你可以通过

    let a = await contract.incrementCounter();
    

    这是小提琴https://studio.nearprotocol.com/?f=m4fcztid8

    【讨论】:

      猜你喜欢
      • 2021-09-02
      • 2022-06-16
      • 2020-08-26
      • 2017-08-19
      • 2020-07-31
      • 2017-08-07
      • 2022-11-22
      • 2022-11-04
      • 2022-09-29
      相关资源
      最近更新 更多