I have studied the work of blockchain by Daniel van Flymen through his source code.
Refer to Ken Formm's study, serverless and blockchain can be used together.
I have modifeid the source code and create a new class file (Blockchain.py). Then, the main function of the function compute can import the class as a Blockchain object.
Here I would like to share my experience developing a serverless application based on Daniel and deploy to Alibaba Cloud Function Compute.
As the sample is currently implement with Flask framework, the simple way is create a new function (Function Compute > Service-Function > Create Function) by selecting the "Template Function" (as follow)
Follow the instructions to config the function by entering the service name, function name, function handler, memory, timeout and instance concurrency and the trigger.
Visual Studio Code is an excellent tool that can implement function for function compute and debug the function locally. It is necessary to install the Aliyun Serverless extension (as below)
After setting up the account connected to Alibaba Cloud, you can download the new function just create at Function Compute, you found that you can implement the function in the main.py file.
If you are going to test the function locally, you need to install Docker. Create a docker account and download docker application by following the instruction in the official web site.
You should also remember to modify the execute environment to python3 as the default template of Flask is executed by python2. (at Line 1)
#!/usr/bin/env python3
If the code is fine after testing, you can deploy the function by right click the function and select Deploy Service.
So, you can take a look and try with API testing tool (such as Postman) :
-
Mine endpoint (url/mine) - GET request
-
Create transaction endpoint (url/transactions/new) - POST request with a JSON body as follow sample:
{ "sender": "my address", "recipient": "Others address", "amount": 10 }
-
Return the full chain endpoint (url/chain) - GET request
-
Register a new node (url/nodes/register) - POST request with a JSON body as following sample:
{ "nodes":["http://x.x.x.x"] }
-
Resolve the chain with Consensus Algorithm (url/nodes/resolve) - GET request
The URL can be found in Trigger Menu under Function Compute.