From 6d2a6bbafb0d19288353e7f0b1f4bb5feac717bd Mon Sep 17 00:00:00 2001 From: Jasmine/kimjimin Date: Tue, 18 Jan 2022 14:15:43 +0900 Subject: [PATCH 1/5] Added troubleshooting contents in readme and deleted an unused file --- README.md | 54 +++++++++++++++- test.js | 183 ------------------------------------------------------ 2 files changed, 53 insertions(+), 184 deletions(-) delete mode 100644 test.js diff --git a/README.md b/README.md index 2f67a6b1..d22616f5 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,10 @@ # caver-js caver-js is a JavaScript API library that allows developers to interact with a -Klaytn node using a HTTP or Websocket connection. +Klaytn node using a HTTP or Websocket connection. + +**NOTE** It is recommended to use [caver-js v1.4.1](https://www.npmjs.com/package/caver-js/v/1.4.1) version when working with Kaikas Web Extension Wallet. +See [Trouble shooting and known issues](#connect-with-kaikas-web-extension) for more details. ## Table of contents @@ -22,6 +25,7 @@ Klaytn node using a HTTP or Websocket connection. * [Error Code Improvement](#error-code-improvement) * [Sample Projects](#sample-projects) * [Github Repository](#github-repository) + * [Trouble shooting and known issues](#trouble-shooting-and-known-issues) * [Related Projects](#related-projects) ## Requirements @@ -296,6 +300,54 @@ The BApp (Blockchain Application) Development sample projects using caver-js are * [Count BApp](https://docs.klaytn.com/bapp/tutorials/count-bapp) * [Klaystagram](https://docs.klaytn.com/bapp/tutorials/klaystagram) +## Trouble shooting and known issues + +### Connect with Kaikas Web Extension + +Kaikas Web Extension Wallet works well only up to [caver-js v1.4.1](https://www.npmjs.com/package/caver-js/v/1.4.1). +Features provided in later versions (caver-js v1.5.0~) may not work with Kaikas Web Extension Wallet. +If the error below occurs when connecting to Kaikas, use caver-js v1.4.1. + +``` +Kaikas only processes one transaction at a time. Open Kaikas and refresh the pending transaction. If the service doesn’t process your transaction for a while, cancel the pending transaction. +``` + +``` +Kaikas는 한 번에 하나의 트랜잭션만 처리합니다. Kaikas를 열어 대기 중인 트랜잭션을 새로고침 해주세요. 만약 대기 상태가 계속된다면 이용 중인 서비스가 트랜잭션을 처리하지 않는 것이니 트랜잭션을 취소바랍니다. +``` + +Although the above error is mostly the case, other errors may occur besides the above error, so if you are using Kaikas Web Extension Wallet, please use caver-js v1.4.1. + +For documents up to caver-js v1.4.1, refer to [here](https://docs.klaytn.com/dapp/sdk/caver-js/v1.4.1). + +### Using webpack >= 5 + +Node.js module polyfills are not provided by default in webpack v5 and later. +Therefore, you need to install the missing modules and add them to the `resolve.fallback` property of the webpack.config.js file in the form below. + +``` +module.exports = { + ... + resolve: { + fallback: { + fs: false, + net: false, + stream: require.resolve('stream-browserify'), + crypto: require.resolve('crypto-browserify'), + http: require.resolve('stream-http'), + https: require.resolve('https-browserify'), + os: require.resolve('os-browserify/browser'), + ... + }, + }, +} +``` + +More information on migrating to webpack v5 can be found [here](https://webpack.js.org/migrate/5/#clean-up-configuration). + +If you are implementing an app using [create-react-app](https://create-react-app.dev/), you can use [react-app-rewired](https://www.npmjs.com/package/react-app-rewired) to add the above polyfills to the webpack.config.js file used by [CRA](https://create-react-app.dev/). +More information on using react-app-rewired with create-react-app can be found [here](https://www.npmjs.com/package/react-app-rewired). + ## Github Repository * [caver-js](https://github.com/klaytn/caver-js) diff --git a/test.js b/test.js deleted file mode 100644 index 50f13fc0..00000000 --- a/test.js +++ /dev/null @@ -1,183 +0,0 @@ -const Caver = require('./index') -// console.log(flatten(Caver)) - -// const provider = new Caver.providers.HttpProvider('https://internal.baobab.klaytn.net:8651', { timeout: 2000 }) -const providerwoTimeout = new Caver.providers.HttpProvider('https://internal.baobab.klaytn.net:8651') -const caver = new Caver(providerwoTimeout) - -async function test() { - const keyring = caver.wallet.keyring.createFromPrivateKey('0x0c66be6f6a0c539be9e99d883e897cdc10cb016a958c9a61485ae57cace5d7bf') - caver.wallet.add(keyring) - - // const kip7 = await caver.kct.kip7.deploy({ - // name: 'Jasmine', - // symbol: 'JAS', - // decimals: 18, - // initialSupply: '100000000' - // }, keyring.address) - - // console.log(kip7) - - // const kip7 = caver.kct.kip7.create('0xf0c398035a88c0dffe23a71bc991a247a24da4d5') - // const receipt = await kip7.transfer(keyring.address, 1000, { from: keyring.address }) - // console.log(receipt) - // console.log(receipt.events.Transfer) - - // const tx = caver.transaction.valueTransfer.create({ - // from: keyring.address, - // to: keyring.address, - // value: 1, - // gas: 250000, - // }) - // await caver.wallet.sign(keyring.address, tx) - // console.log(tx) - - // caver.setProvider(provider) - - // caver.rpc.klay.sendRawTransaction(tx).on('transactionHash', (hash) => { - // console.log(hash) - // }) - - console.log( - caver.abi.decodeLog( - [ - { indexed: true, name: 'from', type: 'address' }, - { indexed: true, name: 'to', type: 'address' }, - { indexed: false, name: 'value', type: 'uint256' }, - ], - '0x00000000000000000000000000000000000000000000000000000000000003e8', - [ - '0x00000000000000000000000060498fefbf1705a3db8d7bb5c80d5238956343e5', - '0x00000000000000000000000060498fefbf1705a3db8d7bb5c80d5238956343e5', - ] - ) - ) -} - -test() - -// const caver = new Caver(`http://141.164.51.33:8551`) -// //// ABI & ByteCode -// const abi = require('./packages/caver-kct/src/kctHelper').kip7JsonInterface // 컨트랙트 ABI -// const byteCode = require(`./packages/caver-kct/src/kctHelper`).kip7ByteCode // 컨트랙트 bytecode -// //// GLOBAL -// let keyring = undefined -// let nonce = undefined -// let curNonce = undefined -// let txMap = {} - -// /** -// * ms 단위로 딜레이를 준다. -// * @param {*} ms 딜레이 타임 (ms) -// */ -// let delay = function(ms) { -// return new Promise(resolve => setTimeout(resolve, ms)) -// } - -// /** -// * @notice deploy tx 생성함수 -// * @param keyring address keyring 정보 -// * @param nonce address 논스값 -// * @param index 호출 인덱스 -// * @author jhhong -// */ -// let makeTxDeploy = async function(keyring, nonce, index) { -// try { -// let name = 'My ERC20 Token' -// let symbol = 'MET' -// let decimals = 18 -// let totalSupply = '100000000000000000000000000' -// let myErc20 = caver.contract.create(abi) -// let data = await myErc20.deploy({ data: byteCode, arguments: [name, symbol, decimals, totalSupply] }).encodeABI() -// let gas = 2000000 -// let rawTx = { from: keyring.address, gas: gas, nonce: nonce, data: data } -// const tx = caver.transaction.smartContractDeploy.create(rawTx) -// await caver.wallet.sign(keyring.address, tx) -// console.log(`트랜잭션 생성 Idx:[${index}], nonce:[${nonce}]`) -// let obj = new Object() -// obj.contents = tx -// obj.created = true -// obj.index = index -// txMap[nonce] = obj -// } catch (error) { -// console.log(error) -// return false -// } -// } - -// /** -// * @notice sendKlay transaction 전송함수 -// * @param nonce 트랜젝션 논스 -// * @param obj 서명된 트랜젝션이 포함된 구조체 -// * @author jhhong -// */ -// let sendTxDeploy = function(nonce, obj) { -// console.log(`트랜잭션 전송 Idx:[${obj.index}], nonce:[${nonce}]`) -// caver.rpc.klay -// .sendRawTransaction(obj.contents) -// .on('transactionHash', function(txHash) { -// console.log(`[transactionHash] Idx:[${obj.index}], Deploy TX:['${txHash}']`) -// }) -// .on('receipt', function(receipt) { -// console.log( -// 'DEBUG', -// `[receipt] Idx:[${obj.index}], Deploy TX:['${receipt.transactionHash}'], BlockNumber:[${parseInt(receipt.blockNumber)}]` -// ) -// delete obj -// }) -// } - -// process.on('deploy-event', function(index) { -// console.log(`Receive deploy-event! index:[%s]`, index) -// if (nonce == undefined) { -// console.log(`nonce does not initialized`) -// return -// } -// let param = nonce++ -// process.emit('proc-deploy', index, param) -// }) - -// /** -// * @notice 테스트 함수 -// * @author jhhong -// */ -// let RunProc = async function() { -// try { -// keyring = await caver.wallet.keyring.createFromPrivateKey('3614732543faf2726ffff58b3243ac8f653e047963edaa6b46b15bcbc6dcd9c4') -// nonce = await caver.rpc.klay.getTransactionCount(keyring.address) -// curNonce = parseInt(nonce) -// await caver.wallet.add(keyring) - -// /** -// * @notice proce-deploy 이벤트 처리함수 -// * @param idx 인덱스 번호 -// * @param nonce keyring address 논스값 -// * @author jhhong -// */ -// process.on('proc-deploy', async function(idx, nonce) { -// try { -// console.log(`start proc-deploy :[${idx}], nonce:[${nonce}]`) -// await makeTxDeploy(keyring, nonce, idx) -// console.log(`nonce:[${nonce}], curNonce:[${curNonce}]`) -// if (nonce == curNonce) { -// while (txMap[curNonce]) { -// sendTxDeploy(curNonce, txMap[curNonce]) -// curNonce++ -// } -// } -// } catch (error) { -// console.log('ERROR', `${error}`) -// process.exit(1) -// } -// }) - -// for (let i = 0; i < 2000; i++) { -// process.emit('deploy-event', i) -// } -// await delay(100000) -// } catch (error) { -// console.log('ERROR', `${error}`) -// process.exit(1) -// } -// } -// RunProc() From 41c7818e6bc4f07311d6aac2c7bf620467dd65b7 Mon Sep 17 00:00:00 2001 From: Jasmine/kimjimin Date: Tue, 18 Jan 2022 17:17:04 +0900 Subject: [PATCH 2/5] Added more documentation link --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d22616f5..623590c2 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ caver-js is a JavaScript API library that allows developers to interact with a Klaytn node using a HTTP or Websocket connection. **NOTE** It is recommended to use [caver-js v1.4.1](https://www.npmjs.com/package/caver-js/v/1.4.1) version when working with Kaikas Web Extension Wallet. +For documents up to caver-js v1.4.1, refer to [caver-js ~v1.4.1 Documentation](https://docs.klaytn.com/dapp/sdk/caver-js/v1.4.1). See [Trouble shooting and known issues](#connect-with-kaikas-web-extension) for more details. ## Table of contents @@ -318,7 +319,7 @@ Kaikas는 한 번에 하나의 트랜잭션만 처리합니다. Kaikas를 열어 Although the above error is mostly the case, other errors may occur besides the above error, so if you are using Kaikas Web Extension Wallet, please use caver-js v1.4.1. -For documents up to caver-js v1.4.1, refer to [here](https://docs.klaytn.com/dapp/sdk/caver-js/v1.4.1). +For documents up to caver-js v1.4.1, refer to [caver-js ~v1.4.1 Documentation](https://docs.klaytn.com/dapp/sdk/caver-js/v1.4.1). ### Using webpack >= 5 From bb8412cb028fe561d1b1d8f7a0a47815d3277126 Mon Sep 17 00:00:00 2001 From: Jasmine/kimjimin Date: Wed, 19 Jan 2022 10:02:55 +0900 Subject: [PATCH 3/5] Disabled deprecate warning event --- packages/caver-klay/src/index.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/caver-klay/src/index.js b/packages/caver-klay/src/index.js index 28600343..ee392f7f 100644 --- a/packages/caver-klay/src/index.js +++ b/packages/caver-klay/src/index.js @@ -168,13 +168,13 @@ const Klay = function Klay(...args) { this.KIP7._klayAccounts = this.accounts this.KIP7.currentProvider = this._requestManager.provider - const kip7Deprecated = - '`caver.klay.KIP7` has been deprecated. `caver.klay.KIP7` works using only `caver.klay.accounts.wallet`. If you are using `caver.wallet` then use `caver.kct.kip7`.' - // Overwrite constructor with deprecate warning - this.KIP7 = util.deprecate(this.KIP7, kip7Deprecated) + // const kip7Deprecated = + // '`caver.klay.KIP7` has been deprecated. `caver.klay.KIP7` works using only `caver.klay.accounts.wallet`. If you are using `caver.wallet` then use `caver.kct.kip7`.' + // // Overwrite constructor with deprecate warning + // this.KIP7 = util.deprecate(this.KIP7, kip7Deprecated) - // Overwrite static deloy method with deprecate warning - this.KIP7.deploy = util.deprecate(this.KIP7.deploy, kip7Deprecated) + // // Overwrite static deloy method with deprecate warning + // this.KIP7.deploy = util.deprecate(this.KIP7.deploy, kip7Deprecated) this.KIP17 = KIP17 this.KIP17.defaultAccount = this.defaultAccount @@ -183,13 +183,13 @@ const Klay = function Klay(...args) { this.KIP17._klayAccounts = this.accounts this.KIP17.currentProvider = this._requestManager.provider - const kip17Deprecated = - '`caver.klay.KIP17` has been deprecated. `caver.klay.KIP17` works using only `caver.klay.accounts.wallet`. If you are using `caver.wallet` then use `caver.kct.kip17`.' - // Overwrite constructor with deprecate warning - this.KIP17 = util.deprecate(KIP17, kip17Deprecated) + // const kip17Deprecated = + // '`caver.klay.KIP17` has been deprecated. `caver.klay.KIP17` works using only `caver.klay.accounts.wallet`. If you are using `caver.wallet` then use `caver.kct.kip17`.' + // // Overwrite constructor with deprecate warning + // this.KIP17 = util.deprecate(KIP17, kip17Deprecated) - // Overwrite static deloy method with deprecate warning - this.KIP17.deploy = util.deprecate(this.KIP17.deploy, kip17Deprecated) + // // Overwrite static deloy method with deprecate warning + // this.KIP17.deploy = util.deprecate(this.KIP17.deploy, kip17Deprecated) // add IBAN this.Iban = utils.Iban From 505b9d89c54de38301fc26a12017185c145e739f Mon Sep 17 00:00:00 2001 From: Jasmine/kimjimin Date: Wed, 19 Jan 2022 10:14:14 +0900 Subject: [PATCH 4/5] Modified readme contents --- README.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 623590c2..1b9a3cfa 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,10 @@ caver-js is a JavaScript API library that allows developers to interact with a Klaytn node using a HTTP or Websocket connection. -**NOTE** It is recommended to use [caver-js v1.4.1](https://www.npmjs.com/package/caver-js/v/1.4.1) version when working with Kaikas Web Extension Wallet. -For documents up to caver-js v1.4.1, refer to [caver-js ~v1.4.1 Documentation](https://docs.klaytn.com/dapp/sdk/caver-js/v1.4.1). -See [Trouble shooting and known issues](#connect-with-kaikas-web-extension) for more details. +**NOTE** +Kaikas Web Extension Wallet is recommended to be used with [features prior to common architecture](https://docs.klaytn.com/dapp/sdk/caver-js/v1.4.1). New features provided in caver-js v1.5.0 (introduced common architecrue) or later are currently not compatible with Kaikas. +Kaikas web extension wallet works fine with functions prior to common architecture, so please use [functions prior to common architecture](https://docs.klaytn.com/dapp/sdk/caver-js/v1.4.1). +Even in the latest version of caver-js, [functions prior to common architecture](https://docs.klaytn.com/dapp/sdk/caver-js/v1.4.1) are provided for backward compatibility. See [Trouble shooting and known issues](#connect-with-kaikas-web-extension) for more details. ## Table of contents @@ -305,9 +306,11 @@ The BApp (Blockchain Application) Development sample projects using caver-js are ### Connect with Kaikas Web Extension -Kaikas Web Extension Wallet works well only up to [caver-js v1.4.1](https://www.npmjs.com/package/caver-js/v/1.4.1). +Kaikas Web Extension Wallet works normally with [functions prior to common architecture](https://docs.klaytn.com/dapp/sdk/caver-js/v1.4.1). Features provided in later versions (caver-js v1.5.0~) may not work with Kaikas Web Extension Wallet. -If the error below occurs when connecting to Kaikas, use caver-js v1.4.1. + +If the following error occurs when using with Kaikas, it must be modified to use the [functions supported by caver-js v1.4.1](https://docs.klaytn.com/dapp/sdk/caver-js/v1.4.1). +For compatibility with the latest version, the same [functions provided by caver-js v1.4.0](https://docs.klaytn.com/dapp/sdk/caver-js/v1.4.1) are provided. ``` Kaikas only processes one transaction at a time. Open Kaikas and refresh the pending transaction. If the service doesn’t process your transaction for a while, cancel the pending transaction. @@ -317,9 +320,10 @@ Kaikas only processes one transaction at a time. Open Kaikas and refresh the pen Kaikas는 한 번에 하나의 트랜잭션만 처리합니다. Kaikas를 열어 대기 중인 트랜잭션을 새로고침 해주세요. 만약 대기 상태가 계속된다면 이용 중인 서비스가 트랜잭션을 처리하지 않는 것이니 트랜잭션을 취소바랍니다. ``` -Although the above error is mostly the case, other errors may occur besides the above error, so if you are using Kaikas Web Extension Wallet, please use caver-js v1.4.1. +Although the above error is mostly the case, other errors may occur besides the above error, so if you are using Kaikas Web Extension Wallet, please use the [functions supported by caver-js v1.4.1](https://docs.klaytn.com/dapp/sdk/caver-js/v1.4.1). +Keep in mind that you **cannot mix features** before and after common architecture. -For documents up to caver-js v1.4.1, refer to [caver-js ~v1.4.1 Documentation](https://docs.klaytn.com/dapp/sdk/caver-js/v1.4.1). +For documents for the functions supported by caver-js v1.4.1, refer to [caver-js ~v1.4.1 Documentation](https://docs.klaytn.com/dapp/sdk/caver-js/v1.4.1). ### Using webpack >= 5 From 6b2075745c31de30f58149234c7f3f6d3fa17911 Mon Sep 17 00:00:00 2001 From: Jasmine/kimjimin Date: Wed, 19 Jan 2022 10:16:56 +0900 Subject: [PATCH 5/5] Fixed lint error --- packages/caver-klay/src/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/caver-klay/src/index.js b/packages/caver-klay/src/index.js index ee392f7f..b1ffefce 100644 --- a/packages/caver-klay/src/index.js +++ b/packages/caver-klay/src/index.js @@ -25,7 +25,6 @@ */ const _ = require('lodash') -const util = require('util') const core = require('../../caver-core') const { formatters } = require('../../caver-core-helpers')