# Embedded MPC Node Example

This example demonstrates how an MPC node can run embedded in a library on a mobile device (iOS and Android) and how the MPC node running on the mobile device can be [dynamically configured](https://builder-vault-tsm.docs.blockdaemon.com/docs/dynamic-node-configuration). This dynamic configuration allows your application to have many mobile devices. Each mobile device holds a share of its own secret signing key, while the other shares of the signing key are stored on the two backend nodes.

## Getting Started

### Prerequisites

First, make sure you have the following ready:

- Docker
- Make. On Debian you can get this by running `sudo apt-get install build-essentials`. On MacOS you can run `brew install make`.
- Go (version 1.22 or later)
- Android Studio and/or Xcode
- Credentials for our [Nexus server](https://nexus.sepior.net/) . Contact the Blockdaemon support team to get these credentials. In the following, we will assume that these are available as the environment variables NEXUS_USERNAME and NEXUS_PASSWORD, but remember to replace these with the actual credentials obtained.

Then open a terminal and clone the Builder Vault demo repository:

```shell
git clone https://gitlab.com/Blockdaemon/tsm-demo.git
```

Once the demo project is fetched, run the two backend MPC nodes:

```shell
docker login -u ${NEXUS_USERNAME} -p ${NEXUS_PASSWORD} bv.sepior.net
make setup
```

When they are up, then start the backend Go server. This is the server that the mobile node will contact, and it will in turn use the TSM SDK to start the relevant operations on the backend nodes:

```shell
cd tsm-demo/mobile/backend
go mod tidy
go run .
```

Finally, fetch the mobile node code and run the mobile node. This can either be done with Xcode/iOS as follows:

```shell
cd tsm-demo/mobile/ios
make Frameworks/Tsm.xcframework
```

Start Xcode, open the project at `tsm-demo/mobile/ios`, and run using, e.g., an iPhone emulator. The emulator should look like this:

You can now do the various Builder Vault operations by clicking on the emulator.

For Android, you can instead do as follows:

```shell
cd tsm-demo/mobile/android
make app/libtsmclient.aar
```

Then open the project at `tsm-demo/mobile/android` with Android Studio, sync Gradle, and run the emulator. This should result in a view like this:

Once running, you can step through the functions in the app (as seen in the two pictures above). The interactions can be observed through the mobile emulator log, within the node log on the app, and the logs of the Builder Vault nodes by running "docker compose logs" in the folder `tsm-demo/mobile/tsm`.

### What’s Next

- [Local Deployment](https://builder-vault-tsm.docs.blockdaemon.com/docs/getting-started-local-deployment)
