Solvedbitcoinjs lib Unable to generate Litecoin address via xpub

I'm attempting to generate/derive an address via a Litecoin xpub key using the following:

var bitcoin = require('bitcoinjs-lib');
import HDNode from "../../bitcoinjs-lib/src/hdnode";

const litecoin = bitcoin.networks.litecoin
const xpub = "Litecoin xpub";
const node = HDNode.fromBase58(xpub);
const address = node.derive(0).getAddress(litecoin);

However, it continues to generate a Bitcoin address. Is there anything I'm doing wrong?

15 Answers

✔️Accepted Answer

@tonychew1986 you are trying to use the litecoin network object, which has different BIP32 constants, if you want to support "both", I recommend you do the following:

let litecoin = bitcoin.networks.litecoin
let litecoinX = Object.assign({}, bitcoin.networks.litecoin, {
  bip32: bitcoin.networks.bitcoin.bip32
})

let a = bitcoin.HDNode.fromBase58(xpub, [litecoin, litecoinX])

Related Issues:

3
bitcoinjs lib Unable to generate Litecoin address via xpub
@tonychew1986 you are trying to use the litecoin network object which has different BIP32 constants ...
55
wallet event-stream dependency attack steals wallets from users of copay
HTTP POST traffic on port 8080 to copayapi.host (which currently resolves to 51.38.112.212 and previ...
23
ccxt Binance error: Timestamp for this request was 1000ms ahead of the server's time.
@jasonmellone I just synched my clock Unfortunately just synching the clock does not work ...
23
freqtrade RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
pip install numpy --upgrade works something has to be updated in the files when you figure out what ...
18
bitcoin test: Remove sync_blocks global
Thanks @brakmic and everyone else for working on issues and making improvements ...
17
bitcoin Windows build appears broken on WSL (buntu okay)
This error is caused by WSL now including Windows PATH In bash if you echo ${PATH} you'll see it's m...
16
bitcoin Compilation error for windows target
Solved the issue Bitcoin uses g++ not gcc $ sudo update-alternatives --config x86_64-w64-mingw32-g++...
15
ccxt Bitfinex margin trading
Hi! Bitfinex has several types of accounts including an exchange account and a margin account ...
14
alpha_vantage Alpha Vantage API Review
@wickenden-g Thank you very much for your incredible review Sadly I am not related to Alpha Vantage ...
12
bitcoin GUI: Who is the GUI being designed for and how do we better avoid bikeshedding?
My personal view and projections on the GUI: I think we should not give up the hope to make Bitcoin ...
12
bitcoin Release schedule for 0.21.0
v0.21.0 (final) was just tagged Here is a proposed release schedule for 0.21.0 the next major releas...
11
bitcoin Release schedule for 0.18.0
0.18 has been branched 🎉. Here is a proposed release schedule for 0.18.0 the next major release of ...
11
bitcoin Bitcoind ThreadRPCServer authentication problems
I was running it on Ubuntu 16 I had rpcuser and rpcpassword in the config file but I was getting 401...
7
gekko [TODO] Simpler configuration
Hey! Great points and you are 100% right Let me quickly explain how we got to the current mess: Gekk...
6
lnd no admin.macaroon
Are you using --no-macaroons when starting lnd? Try also specifying --no-macaroons to lncli ...
4
bitcoin Can't sync signet using 0.21-rc3
178.128.221.177 upgraded to latest aj/202009-signet-generate (69c6e47) I downloaded bitcoin-0.21.0rc...
3
MikaLendingBot Nonce is too small (Bitfinex)
I one of you guys @ououmin @CyberBaby @mark-995 will confirm that multiplying the time by 1000 on th...
3
ccxt insufficent margin issue when creating order
@websharp950223 yes you're right that should be sufficient I would suggest trying to place an order ...
3
ccxt Add a hasCORS boolean property to the Exchange Structure /// Webpack throws error when building in Nuxt
@kireerik @cklester So here's the solution Add the following to your config/nuxt.js file: This will ...
3
ccxt How to make binance "test" buy market order in python with ccxt?
@adam-bhaiji a quick question – are you trying to use spot orders or futures orders? The test param ...
3
ccxt Watching multiple symbols in parallel with WebSockets
@kroitor Brilliant quite pleased with that as I managed after much longer time to cook something tog...
3831
axios Axios catch error returns javascript error not server response
I have exactly the same environment Try this: Modify from console.log(error) to console.log(error.re...
2346
jest Bug: Watch mode on Linux causes a ENOSPC Node.js error
From my findings its not related to Jest at all On Linux (or Mac) we have a max number of system wat...
1975
react RFClarification: why is setState asynchronous?
So here’s a few thoughts This is not a complete response by any means but maybe this is still more h...
1745
react Preventing rerenders with React.memo and useContext hook.
This is working as designed There is a longer discussion about this in #14110 if you're curious ...
1400
TypeScript Quick fix for 'unions can't be used in index signatures, use a mapped object type instead'
You can do this: Though Bar has no index signature (i.e. you can't then do (obj as Bar)[value as Foo...
811
webpack Cannot assign to read only property 'exports' of object '#<Object>' (mix require and export)
The code above is ok You can mix require and export You can't mix import and module.exports. ...
778
yarn Yarn Debian key expiry date updated (EXPKEYSIG 23E7166788B63E1E)
sudo apt-key adv --refresh-keys --keyserver keyserver.ubuntu.com also works to fix this issue for ma...
727
webpack How to exclude node_modules but one
@borm: a solution: Subj as example I create some module in another folder ( /projects/MY_MODULE ) MY...
720
yarn GPG error: https://dl.yarnpkg.com/debian stable InRelease NO_PUBKEY E074D16EB6FF4DE3
Doing curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - again was enough. ...
611
react React Fire: Modernizing React DOM
I love every of these points except the className change For latest status see an update from June 5...
608
angular Angular5.x lazyLoad problem, undefined is not a function
For others that find this issue via Google as i did: I had the same problem when trying to lazy load...
595
react starter kit How to call child component method from parent?
For example you can use Refs to Components approach like so: Demo: https://jsfiddle.net/frenzzy/z9c4...
561
react How should we set up apps for HMR now that Fast Refresh replaces react-hot-loader?
Okay here goes What Is Fast Refresh? It's a reimplementation of hot reloading with full support from...
548
svgo no such file or directory .svgo.yml
I noticed this problem with Yarn after someone had run yarn clean Deleting the .yarnclean file delet...
521
ant motion 模版代码下载下来导入到dva搭建的项目里面,启动时报错(npm start)
开启 JavaScript 就可以了 你好,我下载的Home项目引入到项目工程里面,为了方便,我全部放到了components下面,引入和基本流程没有问题。在家里的win10上面启动没有报错,在win...
516
react native gesture handler Unsupported top level event type "onGestureHandlerStateChange" dispatched
Because my navigators were created asynchronously the handler was registered too late and thus throw...
506
electron Requiring electron outside of main.js causes a TypeError
For anyone encountering this problem in the future and reading this thread Electron version: 1.3.5 O...
499
babel ReferenceError regeneratorRuntime is not defined
I had this issue using rollup with babel I just used this babel config to resolve it : ...
488
webpack nodejs 17: digital envelope routines::unsupported
workaround: Bug report What is the current behavior? Other relevant information: webpack version: 5....
474
meteor [1.4.2.1] Error: ENFILE: file table overflow
I was getting the same after an upgrade to macOS Sierra Turns out macOS have a harsh limit on number...
473
webpack TypeError: Data must be a string or a buffer
Here is a workaround to help you to find the wrong import Using the latest 2.2.0 release although th...
429
vue router how to change document.title in vue-router?
Hi thanks for filling this issue You can simply define title in route's meta I really want set title...
425
babel eslint ESLint: 2.10.0 - Parsing error: Unexpected token =
parser: babel-eslint is OK! I'm using: and getting the following error: Parsing error: Unexpected to...
425
jest Error in Async Example: ReferenceError: regeneratorRuntime is not defined
This worked for me to fix ReferenceError: regeneratorRuntime is not defined in Jest: Then in .babelr...
417
jest babel-jest does not transpile import/export in node_modules when Babel 7 is used
For the record 🐛 Bug Report I started getting the dreaded SyntaxError: Unexpected token import erro...
413
react Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
You're exporting a React element not a component Change to Alternatively at the call site change <Co...
411
react Trigger simulated input value change for React 16 (after react-dom 15.6.0 updated)?
After some research of react source code I got a hack method for react 16: NOTICE: JUST A HACK ...
408
jest "Syntax Error: Invalid or unexpected token" with .png
I had the same error and resolved it by creating a assetsTransformer.js: Then add this to your jest ...
407
jest Watch mode stopped working on macOS Sierra
I had the same issue Upgrading watchman with brew install watchman to v4.7.0 fixed it. ...