Closed carrie143 closed 5 years ago
Hi!
Are you sure the wallet synced when you're checking the balance?
Important: We do not reimplement monero wallet library (libwallet
), we just wrap it in nodejs
plugin.
thank you,I got your point.but how can I Synchronize the wallet?
Normally, right after creating or opening a wallet sync is started automatically. It may take a while and you have to check if the process is finished. The better way to do it is to compare blockchainHeight
(https://github.com/exantech/monero-nodejs-libwallet#blockchainheight) and daemonBlockchainHeight
(https://github.com/exantech/monero-nodejs-libwallet#daemonblockchainheight). Or you may wait for refreshed
event (https://github.com/exantech/monero-nodejs-libwallet#on).
I edited your comment to delete wallet mnemonic. Important: never pass your mnemonic to third parties because it allows anyone to steal your funds.
Decide what you want to do - open an existing wallet or restore wallet from mnemonic. I
f you want just open previously created one you don't have to pass mnemonic
field and use openWallet
function (https://github.com/exantech/monero-nodejs-libwallet#openwallet).
In the code above you trying to restore wallet from 1 block. This sync may take up to 12 hours. We strongly suggest you to use restoreHeight
parameter which should contain approximate height when the wallet has been created. The wallet will sync from the height you passed and the sync time a lot smaller.
Sync time depends on when your wallet has been created and how long it hasn't been synced for. For example, it may receive 1 day block in about several seconds. One year old wallet's restored from mnemonic sync may take dozens on minutes.
I suppose you want to open previously created wallet. In this case just use openWallet
function with proper path
and password
(without mnemonic
). Note that path
may be local and absolute wallet's filename without extension (i.e. .keys
).
To wait when wallet is synchronized you may check for wallet.blockchainHeight() == wallet.daemonBlockchainHeight()
or wait for refreshed
event as described here - https://github.com/exantech/monero-nodejs-libwallet#on
thanks for protect my wallet,and I have understand what you say, What I want to ask is that:when wallet.blockchainHeight() is not equal to wallet.daemonBlockchainHeight(),what I should do to keep the wallet synchronize ,what function I should to call?and how to stop synchronize ? ########### if(wallet.blockchainHeight() === wallet.daemonBlockchainHeight()){ xx stop synchronized xx? }else{ xx keep the wallet to synchronize xx? console.log("balance: " + wallet.balance()); }
You may not stop sync process. After wallet is synchronized this process doesn't consume any significant resources. Most of the time it will sleep and try to check daemon for new blocks once in a while. So your wallet will always be up-to-date.
But if you really want to stop it for some reason you may use https://github.com/exantech/monero-nodejs-libwallet#pauserefresh and https://github.com/exantech/monero-nodejs-libwallet#startrefresh to start it again
1.Do you mean that even thouch my code stop running,the wallet is still synchronizing? 2."wallet.startfresh()" Is it the right way to call the function to start the synchronizion?
1.Do you mean that even thouch my code stop running,the wallet is still synchronizing?
what do you mean by "my code stop running"? If you close your app the wallet won't sync
2."wallet.startfresh()" Is it the right way to call the function to start the synchronizion?
Yes, that's enough
Thank you.I have solve this problem. if I only get the secret spendkey and viewkey and address,Can I recoveryWallet?because I see that recoveryWallet needs mnemonic,in other words,Can I get the mnemonic from spendkey and viewkey?
Normally no. You may get seed (mnemonic) from existing wallet and use to restore. Or if you have both spend secret key and view secret you may use official monero wallet cli to restore it and then use the files with nodejs addon
1,I have saved the wallet file in my computer, 2.and then someone send some monero to my wallet, 3.I use the code to check the balance of wallet,the result is that balance do not change?I want to know why " const monero = require('monero-nodejs-libwallet'); monero.openWallet({ 'path': path.join(__dirname, 'test-wallet'), 'password': '123', 'network': 'mainnet', 'daemonAddress': 'localhost:18081', }).then((wallet) => console.log('New wallet succesfully created: ' + wallet.balance())) .catch((e) => console.log('Failed to create new wallet: ' + e)); "