# Using Builder Vault TSM as an Ethereum Wallet

This example shows how to use the Builder Vault TSM as a simple Ethereum wallet using the [go-ethereum](https://geth.ethereum.org/) library.

The example requires that you have access to a Builder Vault instance configured to allow signing with ECDSA keys. You can, for example, do a [local deployment](https://builder-vault-tsm.docs.blockdaemon.com/docs/blockchain-ethereum) of a Builder Vault instance or use Blockdaemon's [hosted sandbox](https://builder-vault-tsm.docs.blockdaemon.com/docs/getting-started-hosted-sandbox) TSM.

The code first tries to read a master key ID from a file. If the file does not exist, a new master key is generated in the Builder Vault, and the new master key ID is saved to the file for later use. The derived public key for the derivation path `m/42/5` is then obtained from the Builder Vault and converted to an Ethereum account address.

Then, we initialize a go-ethereum client. This requires a URL to an Ethereum node. In the example, we use [Blockdaemon’s BD Transact API](/content/api/overview/index.html) to get access to an Ethereum node in the _Holesky_ test network:

```go
apiKey := strings.TrimSpace(os.Getenv("API_KEY"))
ethereumNodeURL := fmt.Sprintf("https://svc.blockdaemon.com/ethereum/holesky/native?apiKey=%s", apiKey)
ethClient, err := ethclient.Dial(ethereumNodeURL)
```

Alternatively, you can modify the example so it connects to a local Ethereum node that you host yourself or use another third-party Ethereum API provider instead of Blockdaemon API.

Once connected to the Ethereum network, we use the go-ethereum client to get the balance of the account defined by the address `m/42/5`, as well as the current account nonce.

Then we generate an unsigned transaction that sends 0.01 ETH to a destination address. If you want a different address or amount, you can provide these as parameters:

```shell
go run example.go --wei=1000000000000000 --dstAddress=0xab2e2981f6AB817859ffc621Ba7948C4AE535c6f
```

In the next part of the code, we create the payload to be signed, sign it using the Builder Vault, and construct the signed transaction. Finally, we use the go-ethereum client to publish the signed transaction to the Ethereum network.

> 📘
>
> ### Note  
> When you run this example the first time, a new random account will be created, and the balance will be 0 ETH and the nonce will be 0. This will cause the program to print out the account address and stop. To actually transfer funds, you will need to first insert some test funds on the account address and then run the program again.

The example uses the BIP32 derivation path `m/42/5`. See our section about [key derivation](https://builder-vault-tsm.docs.blockdaemon.com/docs/key-derivation-1) for more. See the section about [key import](https://builder-vault-tsm.docs.blockdaemon.com/docs/key-import-and-export) to migrate a key from an external wallet, such as Metamask, to the TSM.

# Code Example

You can find the final code example in our demo repository ([Go](https://gitlab.com/Blockdaemon/tsm-demo/-/blob/main/sdk/golang/crypto_ethereum.go), [node.js](https://gitlab.com/Blockdaemon/tsm-demo/-/blob/main/sdk/nodejs/crypto_ethereum.js)).
