Skip to content
This repository has been archived by the owner on Aug 5, 2023. It is now read-only.

Latest commit

 

History

History
201 lines (162 loc) · 10.3 KB

错误.md

File metadata and controls

201 lines (162 loc) · 10.3 KB
  • Transaction submission failed with error -32000: 'VM Exception while processing transaction: revert' 交易失败, 原因有特别多, 只要不是成功, 基本都会提示这个错误

  • 地址错误 AssertionError: expected promise to be rejected with an error including 'VM Exception while processing transaction: revert' but got 'invalid address (argument="address", value=0, code=INVALID_ARGUMENT, version=address/5.0.5) (argument="_token", value=0, code=INVALID_ARGUMENT, version=abi/5.0.7)' 都是因为地址写错了, 地址必须使用字符串, 且位数不能错误, 该有几位就要有几位.

  • "before each" hook for "executes the trade & charges fees" beforeEach 中的代码有问题, 执行出错

  • TypeError: Cannot read property 'args' of undefined 原因可能是: 没有部署合约到 ganache

  • sol 文件中指定版本时可能会报错 可以修改 truffle-config.js 文件中的版本号 compilers-solc-version

  • 无法使用 module 语法 使用 export 导出时, 需要安装 babel 相关包, 并且要配置 .babelrc 文件

  • Error: Internal JSON-RPC error. 应该是因为我重新部署了一下合约 truffle migrate --reset 然后 metamask 中的账户没有更新, 他还有一些缓存. 解决方法就是将账户 reset 一下就可以了

  • NaN for the children attribute. If this is expected, cast the value to a string. 这是因为代码中的一些字段, 没有对它进行校验, 导致金额是一个 NaN. 根本原因是, 重新部署了一下后, metamask 中的账户金额有问题, 所以才会出现金额是 NaN

  • fill order 时, 如果 metamask 提示 We were not able to estimate gas. There might be an error in the contract and this transaction may fail. 试着在 balance 中的 deposit 点 exchange

  • npm i truffle-hdwallet-provider-privkey@1.0.3 安装这个包时一直报错, 结果发现是版本错误(虽然作者的 gist 仓库写的是 1.0.3) 但实际上应该使用 0.0.3 才可以: npm i truffle-hdwallet-provider-privkey@0.0.3 没有用,下载成功后,这个包用不了,它的package.json 中连依赖都没给。 解决方法时,使用 const HDWalletProvider = require('truffle-hdwallet-provider') 删掉 truffle-hdwallet-provider-privkey

  • Expected parameter 'from' not passed to function. truffle migrate --network kovan 是错误, 原因是 privateKeys 错误, 检查发现 .env 中把账号作为了私钥导入.

  • There was a timeout while attempting to connect to the network at undefined. Check to see that your provider is valid. 可能是因为 .env 中的变量没有加双引号

  • Migrations" could not deploy due to insufficient funds 一言以蔽之:没钱。因为 kovan 测试的人太多了, 发放的 ether 也少. 可以换一个测试网络: ropsten 换了测试网络好, 需要更改 truffle-config.js 中的测试网络名称、provider、network_id 然后部署时也记得要改成 truffle migrate --network 配置中的测试网络名称

  • Invalid JSON RPC response: "" 不知道是啥, 虽然报错了,但是最终还是可以部署到线上。 我也不知道改了多少。 首先我把 2_deploy_contracts.js 中的 feePercent 从 10 改成了 1。 然后我设置了 truffle-config.js 中的 networks.ropsten.networkCheckTimeout = 60000。 而且 HDWalletProvider 的第一个参数, 改成了只有一个账户。 然后最终再部署一次 truffle migrate --network ropsten 终于可以了!!! (对了,gas: 5000000, gasPrice: 25000000000, 这两个值最好不要改,可能会出现 timeout while attempting to connect to the network 错误) 下面给出最终成功部署的结果输出。

$ truffle migrate --network ropsten

Compiling your contracts...
===========================
> Compiling .\src\contracts\Exchange.sol
> Compiling .\src\contracts\Migrations.sol
> Compiling .\src\contracts\Token.sol
> Compiling openzeppelin-solidity\contracts\math\SafeMath.sol
> Artifacts written to D:\truffle\src\abis
> Compiled successfully using:
   - solc: 0.5.0+commit.1d4f565a.Emscripten.clang
WARNING: Ganache forking only supports EIP-1193-compliant providers. Legacy support for send is currently enabled, but will be removed in a future version _without_ a breaking change. To remove this warning, switch to an EIP-1193 provider. This error is probably caused by an old version of Web3's HttpProvider (or ganache < v7)


Migrations dry-run (simulation)
===============================
> Network name:    'ropsten-fork'
> Network id:      3
> Block gas limit: 30000000 (0x1c9c380)


2_deploy_contracts.js
=====================
debugger [ '0xa18C047e08730044E79f696EBf68386b67BD81D2' ]

   Deploying 'Token'
   -----------------
   > block number:        12575653
   > block timestamp:     1657600351
   > account:             0xa18C047e08730044E79f696EBf68386b67BD81D2
   > balance:             4.9524189
   > gas used:            824794 (0xc95da)
   > gas price:           25 gwei
   > value sent:          0 ETH
   > total cost:          0.02061985 ETH


   Deploying 'Exchange'
   --------------------
   > block number:        12575654
   > block timestamp:     1657600354
   > account:             0xa18C047e08730044E79f696EBf68386b67BD81D2
   > balance:             4.902499975
   > gas used:            1996757 (0x1e77d5)
   > gas price:           25 gwei
   > value sent:          0 ETH
   > total cost:          0.049918925 ETH

   -------------------------------------
   > Total cost:         0.070538775 ETH

Summary
=======
> Total deployments:   2
> Final cost:          0.070538775 ETH




Starting migrations...
======================
> Network name:    'ropsten'
> Network id:      3
> Block gas limit: 30000000 (0x1c9c380)


2_deploy_contracts.js
=====================

   Deploying 'Token'
   -----------------
   > transaction hash:    0x7d54db1cb784cfad35e1cedfa563d4cb1aba90259cc0885a3ec1fb5a007aef54
   > Blocks: 1            Seconds: 21
   > contract address:    0xD5191d2829EF07E29Fd20B1C14398826D39FCf49
   > block number:        12575662
   > block timestamp:     1657600392
   > account:             0xa18C047e08730044E79f696EBf68386b67BD81D2
   > balance:             4.9524189
   > gas used:            824794 (0xc95da)
   > gas price:           25 gwei
   > value sent:          0 ETH
   > total cost:          0.02061985 ETH


   Deploying 'Exchange'
   --------------------
   > transaction hash:    0x232cb9ffa86a2a9c4cd73d85a8e1d1fa5aee7a193af8fdb02b6c7298d724582e
Error: Invalid JSON RPC response: ""3
    at Object.InvalidResponse (D:\truffle\node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\Users\tyler\projects\truffle\node_modules\web3\node_modules\web3-core-helpers\src\errors.js:42:1)
    at e.i.onreadystatechange (D:\truffle\node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\Users\tyler\projects\truffle\node_modules\web3\node_modules\web3-providers-http\src\index.js:92:1)
    at e.t.dispatchEvent (D:\truffle\node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\Users\tyler\projects\truffle\node_modules\xhr2-cookies\dist\xml-http-request-event-target.js:27:61)
    at e._setReadyState (D:\truffle\node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\Users\tyler\projects\truffle\node_modules\xhr2-cookies\dist\xml-http-request.js:208:1)
    at e._onHttpRequestError (D:\truffle\node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\Users\tyler\projects\truffle\node_modules\xhr2-cookies\dist\xml-http-request.js:349:1)
    at ClientRequest.<anonymous> (D:\truffle\node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\Users\tyler\projects\truffle\node_modules\xhr2-cookies\dist\xml-http-request.js:252:47)
    at ClientRequest.emit (events.js:315:20)
    at TLSSocket.socketErrorListener (_http_client.js:469:9)
    at TLSSocket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
   > Blocks: 1            Seconds: 13
   > contract address:    0x64a4A6B0806C3FF09741185D275155d3786432A2
   > block number:        12575664
   > block timestamp:     1657600428
   > account:             0xa18C047e08730044E79f696EBf68386b67BD81D2
   > balance:             4.902499975
   > gas used:            1996757 (0x1e77d5)
   > gas price:           25 gwei
   > value sent:          0 ETH
   > total cost:          0.049918925 ETH

Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (D:\truffle\node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\Users\tyler\projects\truffle\node_modules\web3\node_modules\web3-core-helpers\src\errors.js:42:1)
    at e.i.onreadystatechange (D:\truffle\node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\Users\tyler\projects\truffle\node_modules\web3\node_modules\web3-providers-http\src\index.js:92:1)
    at e.t.dispatchEvent (D:\truffle\node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\Users\tyler\projects\truffle\node_modules\xhr2-cookies\dist\xml-http-request-event-target.js:27:61)
    at e._setReadyState (D:\truffle\node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\Users\tyler\projects\truffle\node_modules\xhr2-cookies\dist\xml-http-request.js:208:1)
    at e._onHttpRequestError (D:\truffle\node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\Users\tyler\projects\truffle\node_modules\xhr2-cookies\dist\xml-http-request.js:349:1)
    at ClientRequest.<anonymous> (D:\truffle\node_modules\truffle-hdwallet-provider\dist\webpack:\truffle-hdwallet-provider\Users\tyler\projects\truffle\node_modules\xhr2-cookies\dist\xml-http-request.js:252:47)
    at ClientRequest.emit (events.js:315:20)
    at TLSSocket.socketErrorListener (_http_client.js:469:9)
    at TLSSocket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
   ✓ Saving migration to chain.
   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:         0.070538775 ETH

Summary
=======
> Total deployments:   2
> Final cost:          0.070538775 ETH



Linhieng@LEGION-LHE MINGW64 /d/truffle (main)