Hi there! Welcome to our first tutorial! For this tutorial, we assume that you are familiar with the BigchainDB primitives (assets, inputs, outputs, transactions etc.). If you are not, familiarize yourself with [Key concepts of BigchainDB](../key-concepts-of-bigchaindb/).
We are moving towards an era where the Internet of Things is becoming real. Cars become more connected, devices equipped with sensors can communicate their data, and objects become smarter and smarter. This triggers the need for a digital representation of these devices to store their data in a safe location and to have a complete audit trail of their activity. This is the core idea of the digital twin of an object.
BigchainDB is an ideal solution to create digital twins of smart devices. In this tutorial, you will learn how to build a simple and basic version of a digital twin of your car, which allows its owner to store and update the mileage of the car.
For Alice, you can generate a key pair from a seed phrase using the BIP39 library, so you will just need to remember this particular seed phrase. The code below illustrates that.
In order to create different assets in BigchainDB we will use the Decentralized Identifiers which are identifiers intended for verifiable digital identity that is "self-sovereign". They do not dependent on a centralized registry, identity provider, or certificate authority.(https://w3c-ccg.github.io/did-spec/)
So in this case, each object in the real world as the car, the telemetry box, the GPS device, etc, will be represented by a DID. Each object will have a a tag or cryptochip containing a securely hidden private key.
You will create a DID class that inherits from Orm BigchainDB driver, so DID objects will have all of the methods available in Orm. The `entity` represents the public key of the object itself.
```js
class DID extends Orm {
constructor(entity) {
super(
API_PATH, {
app_id: 'Get one from developers.ipdb.io',
app_key: 'Get one from developers.ipdb.io'
}
)
this.entity = entity
}
}
```
So as each object has a keypair, is possible to create a DID from each object. The objects are "self-sovereign", there is not a central authority that controls them, they will just have a user or another object that will have the ownership over them. As in Orm driver, a model is needed, the default one can be used for this tutorial
After having generated key pairs, you can create assets in BigchainDB. First you will create an asset representing each object. As Decentralized Identifiers are used, you can easily call the `create` method that each of them have and an asset will be created.
As a next step, you need to generate a `CREATE` transaction that represents the user DID in BigchainDB. The user is a self-owned identity, so you will use Alice keypair to create the `userDID`
As you can see, inheriting the Orm class is very easy to create an asset in BigchainDB. The only thing needed is the keypair and the asset.
The id property is set in the DID object. This is the unique identifier of this asset.
Now you can create the DID for the car. The owner of the car is Alice, and she is the one who can transfer this asset in the future, so the Alice keypair is needed to create this asset
Once a transaction ends up in a decided-valid block, it's "etched into stone". There's no changing it, no deleting it. The asset is registered now and cannot be deleted. However, the usage of the metadata field allows you to append new information in the future.
In the Orm driver a so called "Update" in a normal Database, is called "Append" in blockchain, as no data can be really deleted or updated. So in order to track the mileage of the car, the GPS piece will append a new transaction containing the new updated mileage in the metadata.
Since an update of the mileage of a car does not imply any change in the ownership, your transfer transaction will simply be a transfer transaction with the previous owner (car) as beneficiary, but with new metadata in the transaction. So, technically, the car is transferring the GPS to itself and just adding additional, new information to that transaction.
```js
function updateMileage(did, newMileage){
did.myModel
.retrieve(did.id)
.then(assets => {
// assets is an array of myModel
// the retrieve asset contains the last (unspent) state
That's it, we have created a car asset, and every time the car travels new kilometers the `updateMileage` will be called with the new value of it, which leads to a continuous update in the car mileage.