I am using bchaddrjs on client side to convert address to LegacyAddress and CashAddress.
{
"scripts": {
"dev": "vite",
"build": "vite build",
"serve": "vite preview",
"type-check": "tsc --noEmit",
"scripts:svgr:build": "sh ./scripts/svgr/run.sh && npm run prettier:fix && npm run lint:fix",
"lint": "eslint ./src --ext .jsx,.js,.ts,.tsx --quiet --ignore-path ./.gitignore",
"lint:fix": "eslint ./src --ext .jsx,.js,.ts,.tsx --quiet --fix --ignore-path ./.gitignore",
"prettier": "prettier --check \"src/**/*.{ts,tsx}\"",
"prettier:fix": "prettier --write \"src/**/*.{ts,tsx}\"",
"prepare": "husky install",
"test": "jest"
},
"dependencies": {
"bchaddrjs": "^0.5.2",
"bignumber.js": "^9.1.1",
"date-fns": "^2.30.0",
"jwt-decode": "^3.1.2",
"react": "^18.2.0",
"react-admin": "^4.11.1",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@babel/core": "^7.22.5",
"@babel/preset-env": "^7.22.5",
"@svgr/cli": "^6.5.1",
"@types/bchaddrjs": "^0.4.0",
"@types/jest": "^29.5.2",
"@types/lodash": "^4.14.195",
"@types/node": "^18.16.1",
"@types/react": "^18.0.22",
"@types/react-dom": "^18.0.7",
"@typescript-eslint/eslint-plugin": "^5.59.7",
"@typescript-eslint/parser": "^5.59.7",
"@vitejs/plugin-react": "^2.2.0",
"babel-jest": "^29.5.0",
"eslint": "^8.41.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-lodash": "^7.4.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"husky": "^8.0.0",
"jest": "^29.5.0",
"prettier": "^2.8.8",
"ts-jest": "^29.1.0",
"typescript": "^4.6.4",
"vite": "^3.2.0"
}
}
const BchAddressField = () => {
const record = useRecordContext();
try {
const toLegacyAddress = bchaddr.toLegacyAddress(record.verifiableAddress);
const toCashAddress = bchaddr.toCashAddress(record.verifiableAddress);
} catch (e) {
// TODO: fix typeError: Cannot read properties of undefined (reading 'call')
console.log(e);
}
};
TypeError: Cannot read properties of undefined (reading 'call')
at Hash.CipherBase (index.js:7:13)
at new Hash (browser.js:9:8)
at createHash (browser.js:29:10)
at sha256x2 (index.js:8:13)
at Object.encode (base.js:9:20)
at encodeAsLegacy (bchaddr.js:321:20)
at Object.toLegacyAddress (bchaddr.js:110:10)
at BchAddressField (DfcTokensTabs.tsx?t=1691657617814:84:39)
at renderWithHooks (react-dom.development.js:16305:18)
at mountIndeterminateComponent (react-dom.development.js:20074:13)
browser-external:events:9 Module "events" has been externalized for browser compatibility. Cannot access "events.EventEmitter" in client code.
get @ browser-external:events:9
node_modules/readable-stream/lib/_stream_readable.js @ _stream_readable.js:33
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/readable-stream/readable-browser.js @ readable-browser.js:1
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/hash-base/index.js @ index.js:3
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/md5.js/index.js @ index.js:3
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/create-hash/browser.js @ browser.js:3
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/bs58check/index.js @ index.js:3
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/bchaddrjs/src/bchaddr.js @ bchaddr.js:9
__require @ chunk-J43GMYXM.js?v=09e9a855:11
(anonymous) @ bchaddr.js:461
browser-external:events:9 Module "events" has been externalized for browser compatibility. Cannot access "events.EventEmitter" in client code.
get @ browser-external:events:9
node_modules/readable-stream/lib/internal/streams/stream-browser.js @ stream-browser.js:1
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/readable-stream/lib/_stream_readable.js @ _stream_readable.js:40
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/readable-stream/readable-browser.js @ readable-browser.js:1
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/hash-base/index.js @ index.js:3
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/md5.js/index.js @ index.js:3
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/create-hash/browser.js @ browser.js:3
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/bs58check/index.js @ index.js:3
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/bchaddrjs/src/bchaddr.js @ bchaddr.js:9
__require @ chunk-J43GMYXM.js?v=09e9a855:11
(anonymous) @ bchaddr.js:461
browser-external:util:9 Module "util" has been externalized for browser compatibility. Cannot access "util.debuglog" in client code.
get @ browser-external:util:9
node_modules/readable-stream/lib/_stream_readable.js @ _stream_readable.js:55
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/readable-stream/readable-browser.js @ readable-browser.js:1
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/hash-base/index.js @ index.js:3
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/md5.js/index.js @ index.js:3
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/create-hash/browser.js @ browser.js:3
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/bs58check/index.js @ index.js:3
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/bchaddrjs/src/bchaddr.js @ bchaddr.js:9
__require @ chunk-J43GMYXM.js?v=09e9a855:11
(anonymous) @ bchaddr.js:461
browser-external:util:9 Module "util" has been externalized for browser compatibility. Cannot access "util.inspect" in client code.
get @ browser-external:util:9
node_modules/readable-stream/lib/internal/streams/buffer_list.js @ buffer_list.js:14
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/readable-stream/lib/_stream_readable.js @ _stream_readable.js:62
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/readable-stream/readable-browser.js @ readable-browser.js:1
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/hash-base/index.js @ index.js:3
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/md5.js/index.js @ index.js:3
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/create-hash/browser.js @ browser.js:3
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/bs58check/index.js @ index.js:3
__require @ chunk-J43GMYXM.js?v=09e9a855:11
node_modules/bchaddrjs/src/bchaddr.js @ bchaddr.js:9
__require @ chunk-J43GMYXM.js?v=09e9a855:11
(anonymous) @ bchaddr.js:461
browser-external:stream:9 Module "stream" has been externalized for browser compatibility. Cannot access "stream.Transform" in client code.