In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to create an intelligent contract in Ethernet Square". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to create an intelligent contract in Ethernet Square.
Use case: smart contracts in the insurance process
The blockchain follows "no central authority", which is why smart contracts are introduced. But have you ever thought about how to use smart contracts? So, in this part of the ethersquare smart contract, I will explain the use cases of the smart contract in the insurance process.
Let's consider an example of flight delay insurance. Suppose you want to fly from departure A to destination C, but you don't fly directly. So, you decided to transfer through B. Now, your route will be from A to B, and then from B to C, where B is the airport, and you will change your flight. Unfortunately, there is not much time gap between flights from A to B and from B to C. So, if there is any problem, if the flight from A to B is delayed, then you will miss the flight from B to C. After realizing this, in order to avoid heavy losses, you may need a flight delay insurance.
Now, if your flight from A to B is delayed (which will cause you to miss your flight from B to C), you will receive insurance. This is a normal situation. If your flight is delayed, you can apply for insurance. Then, someone will verify and approve the insurance, and finally, you will get your insurance amount. But it's a long process.
How do you use smart contracts to improve the insurance process?
When it comes to financial transactions, especially when you get money, "the sooner the better," isn't it? So, let's see how smart contracts enhance the insurance process. Smart contracts are digital contracts that are executed automatically when certain conditions are met. If there is a flight delay, you can write a smart contract to pay the amount of insurance to the person who chooses flight delay insurance. Therefore, when the flight is delayed and the delay is recorded by the system, the insurance will be paid immediately.
OK! The insured amount will be paid in a few seconds. This is how smart contracts implement the process simply and quickly.
Benefits of smart contracts
You have seen in the above example how smart contracts enhance the financial process. Smart contracts have more benefits than fast trading. Here, I list some other benefits of using smart contracts:
Automation: smart contracts automatically perform all steps.
No intermediary: when you use a smart contract, you don't need an intermediary to get the job done, because everything will be handled by the smart contract.
Cost-effectiveness: the use of smart contracts can save the transaction fees charged by banks and the service fees of intermediaries, if any.
Now that we know how to use smart contracts to make the world faster, let's experience this ethernet smart contract course.
Installation prerequisites
For the Ethernet Square Smart contract tutorial, we need five important applications:
NodeJS
NPM
Ethereum
Truffle
Solidity Compiler
Install NodeJS
NodeJS is a JavaScript framework for building server applications. Because we are using a private network, NodeJS can easily build network applications.
To install Nodejs, run the following command in the terminal:
$sudo apt-get install nodejs installs NPM
NPM stands for Node Package Manager and is used to run Nodejs applications.
To install NPM, run the following command in the terminal:
$sudo apt-get install npm installation of Tai Tai Fong
Etay Fong is a distributed computing platform based on open source and common block chains for building decentralized applications.
To install Ethernet Square, run the following command in the terminal:
$sudo apt-get install software-properties-common$ sudo add-apt-repository-y ppa:ethereum/ethereum$ sudo apt-get update$ sudo apt-get install ethereum install Truffle
Truffle is the development environment, test framework and asset pipeline of ethernet Blokchains.
To install Truffle, run the following command in the terminal:
$npm install-g truffle install Solidity Compiler
Solidity is a programming language for writing intelligent contracts. To run smart contracts on our system, we must install Solidity Compiler.
To install Solidity Compiler, run the following command in the terminal:
$sudo npm install-g solc configuration Genesis Block
Genesis Block is the starting point for Blockchain, and we need a genesis file to start Blockchain. In this part of the ethersquare smart contract, we will write a Genesis file and configure it to allow us to run the smart contract.
Let's first create a new directory, and then create a genesis file in that directory:
$mkdir ethereum-network$ cd ethereum-network$ nano genesis.json
Now, enter the following line in the genesis.json file:
{"config": {"chainId": 2019, "homesteadBlock": 0, "eip155Block": 0, "eip158Block": 0}, "alloc": {}, "difficulty": "2019"gasLimit": "99999999999999"}
Save and exit.
Run the dedicated network of ethernet
In this Etheruem Smart contract tutorial, we will deploy the Ethernet Square Smart contract on a private network. Therefore, to start this network, we will use the following command:
$geth-- datadir. / dataDir init. / genesis.json
Geth-- port 4321-- networkid 1234-- datadir=./dataDir-- rpc-- rpcport 8543-- rpcaddr 127.0.0.1-- rpcapi "eth,net,web3,personal,miner"
Before going any further, let me explain some of the important parameters used in the above command:
Datadir: the directory where Blockchain-related data is stored.
Rpc: enable the HTTP-RPC server.
Rpcport and rpcaddr are used to set the port and address of the network, respectively.
Rpcapi: allows us to use different API to interact with the ethernet network.
Connect Geth to the Ethernet Square private block chain
The Geth console is the console where we can interact with the Ethernet Square private block chain. To connect Geth to the Ethernet Square private block chain, open a new terminal and run the following command:
$geth attach http://127.0.0.1:8543
Now that we are in the Geth console, we can communicate with the blockchain.
Create an Etay Fong account
To make any transaction, we need an account. In this part of the Smart contract tutorial in Ethernet Square, we will see how to create a new Ethernet Square account from the Geth console.
Following the steps so far, we are already in the Geth console. To create a new account, run the following command in the Geth console:
> personal.newAccount ('seedphrase')
Replace seedphrase with the password you want to set for this account.
We have created a new account, but this account does not have ether. We need to start mining. To start digging, we need to unlock the account. Let's unlock the account and start digging.
Personal.unlockAccount (web3.eth.coinbase, "seedphrase") > miner.start ()
As mining continues to occur, some ether will be deposited into the account.
Note: these ether are virtual ether and have no real value.
To check the ether balance in the account, we will run the following command:
Web3.fromWei (eth.getBalance (eth.coinbase), "ether")
When you run this command regularly, you will see an increase in ether due to mining.
To stop mining, run the following command:
Miner.stop () creates an intelligent contract to create a truffle project in eTaifang
Now that we have our private blockchain ready, we will see how to use Truffle to create ethernet smart contracts. In this tutorial, we will create a simple "Hello World" ethernet square smart contract.
First, let's first create a new directory to store the Truffle project. Then in this directory, we will create a new Truffle project. Open a new terminal and run the following command:
$mkdir truffle$ cd truffle$ truffle init
The truffle init command creates all the necessary files required for the Truffle project.
Now that we are ready to deploy all the contents of the ethersquare smart contract, let's write a "Hello World" smart contract.
Write a "Hello World" smart contract
All contracts should be written in the contracts directory. We will change to this directory and create a contract named HelloWorld.sol and add the following line to this file:
Pragma solidity ^ 0.4.15 position contract HelloWorld {string public message; function Hello () public {message = "HelloWorld!";}}
This is it! But this smart contract cannot be executed alone. We will have to do some configuration for it.
Configure Truffle Migration
To migrate our smart contract, we must add a file to the migrations directory of the truffle directory. In this directory, we will add a file called 2_deploy_contracts.js that contains the following:
Var HelloWorld = artifacts.require (". / HelloWorld.sol"); module.exports = function (deployer) {deployer.deploy (HelloWorld);}
Save and exit.
To run Truffle on our network, we need to edit the truffle.js file in the truffle directory. Open this file and enter the following:
Module.exports = {rpc: {host: "localhost", port:8543}, networks: {development: {host: "localhost", port:8543, network_id: "*", from: "0xfa2361236b5ac8079cb6cf250e5284922ed9ba9a", gas: 20000000}
Note: replace the from address with the address of the account you created in the previous step.
Execute the ethernet square intelligence contract
In the last section of the Ethernet Square Smart contract tutorial, we will learn how to deploy our Hello World smart contract on our Ethernet Square private network.
Compile and deploy smart contracts
Before we can execute the smart contract, we must first compile and deploy it to our ethernet private network. We will do this using the following command:
$truffle compile
Now, we must unlock our account and start digging. Use the Geth console to return to the terminal and run the following command:
> personal.unlockAccount (web3.eth.coinbase) > miner.start ()
Then, return to the terminal with truffle as the current working directory and run the following command:
$truffle migrate
Wait for the deployment to complete.
Execute a smart contract on a private Ethernet block chain
To execute the Hello World smart contract, we must go to the Truffle console. Run the following command to do this:
$truffle console
You will now be on the Truffle console. To execute a smart contract, run the following command:
> var first_contract > HelloWorld.deployed (). Then (function (instance) {first_contract = instance;}) > dApp.message.call ()
At this point, I believe you have a deeper understanding of "how to create an intelligent contract in Ethernet Square". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.