aspectron / kaspa-wallet-deprecated

Kaspa Wallet framework
10 stars 9 forks source link

Subscribing to derived address #9

Open emochka2007 opened 7 months ago

emochka2007 commented 7 months ago

Hello, I would like to know - is there a way to subscribe to the events of the derived addresses? When I was using main receive address, i was getting the events, but when i tried to send KAS to derived address, no events emitted. Here i derive address with index

deriveAddress(index: number) {
        // const dType = deriveType === 'receive' ? 0 : 1;
        const dType = '0'
        const seedWallet = Wallet.fromMnemonic(KEYCHAIN_SEED, { network: 'kaspa', rpc: this.rpc })
        const privateKey = seedWallet.HDWallet.deriveChild(`m/44'/972/0'/${dType}'/${index}'`)
        const addressManager = new AddressManager(privateKey, 'kaspa')
        const newAddr = addressManager.getAddresses(1, 'receive')

        return {
            publicKey: newAddr[0].address,
            privateKey: addressManager.receiveAddress.keypairs[newAddr[0].address].toString(),
        }
    }

Here, I'm subscribing to the events.

 const wallet = Wallet.fromMnemonic(
            KEYCHAIN_SEED,
            { network: 'kaspa', rpc: this.rpc },
            {
                addressDiscoveryExtent: 1000,
            }
        )

  wallet.on('balance-update', balance => {
            this.logger.warn('BALANCE UPDATED')
            this.logger.debug(JSON.stringify(balance))
        })