Dapps

試圖獲取布爾變數的值“應該設置初始設置”

  • October 17, 2021

我有以下公共變數:

bool public saleIsActive = false;

但是當我嘗試從如下測試中訪問時:

let isActive = await myContractInstance.salesIsActive.call();

我收到以下錯誤:

1) Contract: MyContract
  should have the initial setting set:
TypeError: Cannot read property 'call' of undefined
 at Context.it (test/myContract.js:21:55)
  1. "should have the initial setting set"是您的特定測試的名稱:您可以在"test/myContract.js". 它與錯誤本身無關。
  2. 實際錯誤是“TypeError:無法讀取未定義的屬性‘呼叫’”。當您呼叫myContractInstance.salesIsActive.call()時,這意味著myContractInstance.salesIsActive未定義。
  3. 將測試中的行更改為:let isActive = await myContractInstance.salesIsActive();這是正確的語法。

$$ edit: as Jean pointed out in the comments, this does the same, it’s just sugar syntax $$ 4. 問題是一個錯字:您正在設置saleIsActive但呼叫salesIsActive.

引用自:https://ethereum.stackexchange.com/questions/111696