使用 nodejs 部署到 appChain 测试链问题


#1

有社区的小伙伴反应:
在 使用 nodejs 部署到 appChain 测试链的时候
mac 和 windows下都有这个问题


#2

使用这个js 脚本部署 nervos的Appchain, 提示 Error: Returned error: InvalidVersion


#3
https://node.cryptape.com

这条链的 rpc 协议版本从 0 升级到 1 了, 需要使用最新的 SDK(https://www.npmjs.com/package/@appchain/base) 并且交易结构体中的 version 字段要从 0 变为 1


#4

另外我们还提供了新的部署合约的方式, 在类似 remix 的环境下(https://appchain-ide.cryptape.com)做部署


#5

chainId要用哪个呢

  { from: '0x9Dd6b006f6e73D0dEd2ca62eb8c80C4afba11F6c',
  privateKey:   '0x111',
  value: '0x0',
  nonce: 999990,
  quota: 1000000,
  chainId: 1,
  version: 1,
  validUntilBlock: 999999 }
(node:56433) UnhandledPromiseRejectionWarning: Error: Returned error: BadChainId
    at Object.ErrorResponse (/Users/flora/workspace/nervos/first-forever/node_modules/web3-core-helpers/src/errors.js:29:16)
    at /Users/flora/workspace/nervos/first-forever/node_modules/web3-core-requestmanager/src/index.js:140:36
    at XMLHttpRequest.request.onreadystatechange (/Users/flora/workspace/nervos/first-forever/node_modules/web3-providers-http/src/index.js:91:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/flora/workspace/nervos/first-forever/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
    at XMLHttpRequest._setReadyState (/Users/flora/workspace/nervos/first-forever/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
    at XMLHttpRequest._onHttpResponseEnd (/Users/flora/workspace/nervos/first-forever/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
    at IncomingMessage.<anonymous> (/Users/flora/workspace/nervos/first-forever/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)
    at IncomingMessage.emit (events.js:187:15)
    at endReadableNT (_stream_readable.js:1094:12)
    at process.internalTickCallback (internal/process/next_tick.js:72:19)
(node:56433) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:56433) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

#6

chainId 用 1 就可以, 这个可以通过 sdk 的 get meta data 接口获取.

需要注意的是往 0.19 的链发 version = 1 的会提醒 badChainId, 只有 0.20 的链需要设置 version = 1

可以通过 getMetaData 接口查看链的协议版本号


#7

更新了@appchain/base, version和rpc node后,现在出现了ABI的错误:

(node:58157) UnhandledPromiseRejectionWarning: Error: Malformed ABI
    at Method.exports.outputAbiFormatter [as outputFormatter] (/Users/flora/workspace/nervos/first-forever/deploy/node_modules/@appchain/base/lib/utils/outputFormatters.js:15:15)
    at Method.formatOutput (/Users/flora/workspace/nervos/first-forever/deploy/node_modules/web3-core-method/src/index.js:163:54)
    at sendTxCallback (/Users/flora/workspace/nervos/first-forever/deploy/node_modules/web3-core-method/src/index.js:473:33)
    at /Users/flora/workspace/nervos/first-forever/deploy/node_modules/web3-core-requestmanager/src/index.js:147:9
    at XMLHttpRequest.request.onreadystatechange (/Users/flora/workspace/nervos/first-forever/deploy/node_modules/web3-providers-http/src/index.js:91:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/flora/workspace/nervos/first-forever/deploy/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
    at XMLHttpRequest._setReadyState (/Users/flora/workspace/nervos/first-forever/deploy/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
    at XMLHttpRequest._onHttpResponseEnd (/Users/flora/workspace/nervos/first-forever/deploy/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
    at IncomingMessage.<anonymous> (/Users/flora/workspace/nervos/first-forever/deploy/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)
    at IncomingMessage.emit (events.js:187:15)
    at endReadableNT (_stream_readable.js:1094:12)
    at process.internalTickCallback (internal/process/next_tick.js:72:19)
(node:58157) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:58157) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

#8

这是 CITA 0.20 的新特性, 要获取最新块上的数据不能标记 block 为 ‘latest’, 而要改为 ‘pending’. 所以你在获取 abi 的时候要加上 blockNumber 参数, 简单来说就是

  appchain.base.getAbi(receipt.contractAddress, 'pending')

#9

可以了 多谢 @keith :)