Web3js

在 ERC721 合約上呼叫 transferFrom() 時出現“錯誤:無法辨識發件人帳戶”

  • September 15, 2021

我在將 ERC721 代幣的所有權轉移到已部署的控股契約時遇到問題。

我在執行時遇到的錯誤truffle test如下 -使用已部署的 Holding 合約Error: sender account not recognized呼叫transferFrom()ERC721 合約上的函式時。

我在打電話之前已經成功批准了持有契約,transferFrom()所以這不是問題,但我不知道嘗試將 NFT 轉移到持有契約的錯誤在哪裡。

合約和測試文件位於: https ://github.com/sharad-s/DAOjo

在我的測試中導致此錯誤的特定程式碼行是第 120 行DAOjo/test/test.js

要重新創建此錯誤:

  • 複製回購
  • 全域安裝松露
  • 執行 ganache 本地區塊鏈實例(埠 8545)
  • truffle test在這個 repo 的根目錄下執行

以下是錯誤堆棧跟踪:

Contract: Crowdsale
DAOToken
1e+23
     ✓ should have a total supply of: 1e+23
     ✓ should have transferred 1e+23 to Crowdsale
   Crowdsale
Wei Raised:  1000000000000000000
Buyer Balance:  1000000000000000000
     ✓ should accept ETH payments (144ms)

Contract: NFTTokenMetaDataEnumerableMock
 NFT Registry
     ✓ Should have a total of 0 tokens when created
NFT APPROVED FOR:  0x3a0a837952964bdf3e751ba838e04b9a1752d94a
HOUSE OWNER:  0x6e4679ddb735556a47dd548489dfab641752afd5
SPV:  0x3a0a837952964bdf3e751ba838e04b9a1752d94a
DAO TOKEN BALANCE OF BUYER 1:  BigNumber { s: 1, e: 3, c: [ 1000 ] }
     1) Should approve and transfer token to SPV contract

   Events emitted during test:
   ---------------------------

   Transfer(from: <indexed>, to: <indexed>, value: 1000)
   Transfer(from: <indexed>, to: <indexed>, value: 1000)
   Transfer(from: <indexed>, to: <indexed>, value: 1000)
   Transfer(from: <indexed>, to: <indexed>, value: 0)
   Approval(owner: <indexed>, spender: <indexed>, value: 0)

   ---------------------------


 4 passing (3s)
 1 failing

 1) Contract: NFTTokenMetaDataEnumerableMock
      NFT Registry
        Should approve and transfer token to SPV contract:
Error: sender account not recognized
 at Object.InvalidResponse (/Users/sharad/.nvm/versions/node/v8.9.4/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:38:1)
 at /Users/sharad/.nvm/versions/node/v8.9.4/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/requestmanager.js:86:1
 at /Users/sharad/.nvm/versions/node/v8.9.4/lib/node_modules/truffle/build/webpack:/packages/truffle-provider/wrapper.js:134:1
 at XMLHttpRequest.request.onreadystatechange (/Users/sharad/.nvm/versions/node/v8.9.4/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/httpprovider.js:128:1)
 at XMLHttpRequestEventTarget.dispatchEvent (/Users/sharad/.nvm/versions/node/v8.9.4/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:64:1)
 at XMLHttpRequest._setReadyState (/Users/sharad/.nvm/versions/node/v8.9.4/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:354:1)
 at XMLHttpRequest._onHttpResponseEnd (/Users/sharad/.nvm/versions/node/v8.9.4/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:509:1)
 at IncomingMessage.<anonymous> (/Users/sharad/.nvm/versions/node/v8.9.4/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:469:1)
 at endReadableNT (_stream_readable.js:1055:12)
 at _combinedTickCallback (internal/process/next_tick.js:138:11)
 at process._tickCallback (internal/process/next_tick.js:180:9)

謝謝!

您只能向from您的節點(在本例中為 ganache)知道私鑰的帳戶發送交易。在這段程式碼中:

const transferFrom = await _HouseNFTRegistry.transferFrom(
   houseOwner,
   _spvHoldingCrowdsale.address,
   1,
   { from: _spvHoldingCrowdsale.address, to: _HouseNFTRegistry.address }
);

您正在嘗試從合約地址發送交易,這是您無法做到的。(沒有人知道該地址的私鑰。)

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