mapping 語法

語法

判斷是否存過資料

避免覆蓋原資料

  let user = User.load(userId)
  if (user === null) {
    user = new User(userId)
  }

獲取區塊時間

event.block.timestamp.toI32()

schema

timestamp: Int!

數字運算

userPairBalance.balance.minus(value)
userPairBalance.balance.plus(value)

schema

balance: BigDecimal!

呼叫合約的 function

https://thegraph.com/docs/en/developer/assemblyscript-api/#access-to-smart-contract-state

處理相關 revert 情況

使用 try_ : https://thegraph.com/docs/en/developer/assemblyscript-api/#handling-reverted-calls

Schema 內含 schema

schema

要用 null 判斷 entity 是否存過,不能用 or

以下會出現錯誤:

設定屬性不能用 or 要直接寫在 === null 判斷內。

另外如果變數沒用到還是要註解,不然仍會編譯進去產生錯誤

正確用法:

Last updated

Was this helpful?