diff --git a/_src/_guides/tutorial-piece-of-art.md b/_src/_guides/tutorial-piece-of-art.md new file mode 100644 index 0000000..ff6c6d1 --- /dev/null +++ b/_src/_guides/tutorial-piece-of-art.md @@ -0,0 +1,150 @@ + +--- +layout: guide + +title: "Tutorial: How to create a digital track of a piece of art" +tagline: Build a digital track of a famous paint that you own +header: header-car.jpg +order: 2 + +learn: > + - How BigchainDB can be used to record dynamic parameters of an asset + + - How assets can be used on BigchainDB to represent real objects + + - How to make a `CREATE` transaction to digitally register an asset on BigchainDB + + - How asset to create `TRANSFER` transactions to change the ownership of an asset in BigchainDB +--- + +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/). + +# About digital object + +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. + +Let's get started! + +{% include_relative _setup.md %} + +# Create a key pair + +In BigchainDB, users are represented as a private and public key pair. In our case, a key pair for Alice will be created. Alice will be the owner of the car, and she will be the only one able to update the mileage of the car. Using her public key, anyone can also verify that Alice is the creator of the car. + +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. + +```js +const alice = new BigchainDB.Ed25519Keypair(bip39.mnemonicToSeed('seedPhrase').slice(0,32)) +``` + +# Digital registration of an asset on BigchainDB + +After having generated a key pair, you can create transactions in BigchainDB, so you can start registering your paint in BigchainDB. This corresponds to an asset creation. In our case, an asset will represent an object in real life, namely a paint. This asset will live in BigchainDB forever and there is no possibility to delete it. This is the immutability property of blockchain technology. + +The first thing needed is the definition of the asset field that represents the car. It has a JSON format: + +```js +const paint = { + name: 'Meninas', + author: 'Diego Rodríguez de Silva y Velázquez' + place: 'Madrid', + year: '1656' +} +``` + +As a next step, you need to generate a `CREATE` transaction to link the defined asset to the user Alice. There are three steps to post this transaction in BigchainDB, first you create it, then sign it and then send it. There are different methods for each step: + +```js +function createPaint() { + // Construct a transaction payload + const txCreateCar = BigchainDB.Transaction.makeCreateTransaction( + // Asset field + { + ...paint, + }, + // Metadata field, contains information about the transaction itself + // (can be `null` if not needed) + // Initialize the mileage with 0 km + { + datetime: new Date().toString(), + location: 'Madrid', + value: { + value_eur: '2500000€', + value_btc: '220', + } + }, + // Output. For this case we create a simple Ed25519 condition + [BigchainDB.Transaction.makeOutput( + BigchainDB.Transaction.makeEd25519Condition(alice.publicKey))], + // Issuers + alice.publicKey + ) + // The owner of the paint signs the transaction + const txSigned = BigchainDB.Transaction.signTransaction(txCreateCar, + alice.privateKey) + + // Send the transaction off to BigchainDB + conn.postTransaction(txSigned) + // Check the status of the transaction every 0.5 seconds. + .then(() => conn.pollStatusAndFetchTransaction(txSigned.id)) + .then(res => { + document.body.innerHTML +='