Create Asset Definition
As the first step, let’s create an asset say “Car” in our example, which has set of properties. Define them in your model file of composer (.cto)
The above defined asset Car has three properties named id, name, owner. And in order to create a Car we need to have a transaction, thus define a transaction model as below.
As you can notice, here we’re not mentioning the owner while creating the car, since we’ll be using the getCurrentParticipant()
method inside transaction processor function to get the current user and define the owner.
Now since we’ve everything in our network, let’s update the network with the following commands.
Creating EndPoint For Transaction
Next up is to create an endpoint for transaction submission. We do it with express js as follows.
This is very similar to the ping method, we’re getting the transaction data from the request and passing it to createCar
method in our MyNetwork Class.
This returns a null
if the transaction is submitted successfully, else catch block is called with the captured error.
The only thing to have in mind is that we need to specify the $class
in transactionData and convert it to resource format from JSON before passing it to submitTransaction
function.
Subscribe to our newsletter
Get the latest updates from our team delivered directly to your inbox.
Related Posts
10 Gems in Ruby that you will love
Let's go back to basics with Ruby on Rails and see some of the Gems that we use everyday at skcript. #StartWithSkcript
#100DaysOfCommits
Our CTO, Swaathi, talks about our commitment to the #100DaysOfCommit challenge. Join us.
18 Python packages you should be using right now
Let us look at some python packages that will get you started on your machine learning path #StartWithSkcript