Gnosis-Safe
使用 ethAdapter 簽署 safeTransaction 時出現“TypeError:無法讀取未定義的屬性(讀取 ‘arrayify’)”
使用 Safe Core SDK 簽署簡單的乙太幣轉賬交易時出現以下錯誤。
const ethAdapter = new EthersAdapter({ ethers: ether3, signer: ether3.getSigner(0), }) const safeSdk = await Safe.create({ ethAdapter, safeAddress }) let transaction = { to: 'receiver_address', data: '0x', value: '1000000000000000000', } transaction.nonce = await safeService.getNextNonce(safeAddress) const safeTransaction = await safeSdk.createTransaction(transaction) await safeSdk.signTransaction(safeTransaction) // this is throwing error
TypeError: Cannot read properties of undefined (reading 'arrayify') at EthersAdapter.signMessage (EthersAdapter.js?298f:103:1) at generateSignature (index.js?1e12:55:1) at async Safe.signTransaction (Safe.js?3512:258:1)
無法理解為什麼會發生這種情況,因為以前我使用的是 web3Adapter 並且沒有給出任何此類錯誤。
編輯(2022 年 1 月 25 日):
import { ethers } from 'ethers' const ether3 = new ethers.providers.Web3Provider(window.ethereum) // I am using different provider but it is similar to metamask const ethAdapter = new EthersAdapter({ ethers: ether3, signer: ether3.getSigner(0), }) const safeSdk = await Safe.create({ ethAdapter, safeAddress }) let transaction = { to: 'receiver_address', data: '0x', value: '1000000000000000000', } transaction.nonce = await safeService.getNextNonce(safeAddress) const safeTransaction = await safeSdk.createTransaction(transaction) await safeSdk.signTransaction(safeTransaction) // this is throwing error
signMessage
來自 EthersAdapter 類的方法:signMessage(message) { const messageArray = __classPrivateFieldGet(this, _EthersAdapter_ethers, "f").utils.arrayify(message); return __classPrivateFieldGet(this, _EthersAdapter_signer, "f").signMessage(messageArray); }
signMessage
錯誤在類的方法中引發EthersAdapter
:signMessage(message: string): Promise<string> { const messageArray = this.#ethers.utils.arrayify(message) return this.#signer.signMessage(messageArray) }
where
this.#ethers.utils
似乎是未定義的。請確保您的
ether3
對像是有效的,它應該像這樣導入:import { ethers } from "ethers"
引發此錯誤是因為
0x
根據 ethers 不是有效的“arrayify”。改變
let transaction = { to: 'receiver_address', data: '0x', value: '1000000000000000000', }
到
let transaction = { to: 'receiver_address', data: '0x00', value: '1000000000000000000', }