# Custom electrum servers with the BDK-Kotlin wallet

> A quick guide on how the user can change the wallet's electrum servers.

By Tang Yetong. Published June 28, 2022. 3 min read. Category: blockchain. Tags: BDK-Kotlin, Bitcoin, Electrum, Privacy.
Read it with the interactive demos: https://tangyetong.com/blog/custom-electrum-servers-bdk-kotlin

A quick guide on how the user can change the wallet's electrum servers.

## Why

Lets say, for example, you have promised your wallet users absolute anonymity when using it. 
Nobody should be able to come close to figuring out what you or your users are doing on the blockchain.
Perhaps you heard from a friend that the public blockchain indexing services are collecting the data of people who used it.

Although that is *highly* unlikely, the possibility that a public electrum server *can* conduct malicious activities might not sit well with everyone. 
To give an idea of what they *can* do :
 * Lie to you and tell you you have coins that you don't
 * Refuse to relay your spending transactions

It can't however :
 * Give you a fake receive address
 * Steal your wallet private keys

Electrum shares your wallet addresses with the server you are connected to so the server sees all your transactions. 

If you have your own electrum server set up, or just simply want to switch to different electrum addresses on the fly, it is trivially easy to accomplish using the [`BDK-Kotlin`](https://github.com/bitcoindevkit/bdk-kotlin) library.

## How

All you have to do is create a new `BlockchainConfig` object with the new electrum server URL, create the new `Blockchain` object off it, and finally sync the `Wallet` to the new `Blockchain`.

```
val newBlockchainConfig = BlockchainConfig.Electrum(ElectrumConfig(customElectrumURL, null, 5u, null, 10u))
val newBlockchain = Blockchain(blockchainConfig)
wallet.sync(newBlockchain)
```

And that's it! You are now connected to a new public electrum server, or you own custom run one. 

Do note, however, if the electrum server URL you have passed in is invalid (does not point to a server), the app might freeze. 
Do provide your own error handling either on the UI or the backend side.
