Web3js
錯誤:提供的地址“6.963865902119903e+47”無效
完整的錯誤日誌:
formatters.js:471 Uncaught Error: Provided address "6.963865902119903e+47" is invalid, the capitalization checksum test failed, or its an indrect IBAN address which can't be converted. at Object.inputAddressFormatter (formatters.js:471) at Object.set [as address] (index.js:92) at Contract (index.js:296) at new Contract (index.js:273) at index.html:23
當我嘗試在 Chrome 瀏覽器中執行 index.html 時出現此錯誤。我預計這與此程式碼是從本教程中複製的事實有關,該教程已有 1.5 年的歷史。
這是我的目錄
原來我忘了把合約的實例地址放在引號裡!
請參閱此程式碼段的最後一行:
var ethereumSessionInstance = new web3.eth.Contract([ { "constant": false, "inputs": [ { "name": "_myInt", "type": "uint256" } ], "name": "setTheInt", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "getTheInt", "outputs": [ { "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "inputs": [ { "name": "_myInt", "type": "uint256" } ], "payable": false, "stateMutability": "nonpayable", "type": "constructor" } ], "0x79fB0E00F4dB8812b04Ae84816BbccAF941E5c90");
通過在地址周圍加上引號解決了該錯誤。
在 Javascript 中,類型
0x79fB0E00F4dB8812b04Ae84816BbccAF941E5c90
是Number
.然而,這個數字的值大於
Number.MAX_SAFE_INTEGER
53 位長。Solidity 地址類型為 160 位長,它們作為字元串傳遞給 web3.js 函式或從 web3.js 函式傳遞。
因此,您應該始終在 Javascript 程式碼中的任何地址值周圍使用引號。