Hauv tsab xov xwm no peb yuav txheeb xyuas cov khoom thiab cov hauv paus ntsiab lus uas muaj rau txhua tus blockchains. Tom ntej no, cia saib cov teeb meem uas tuaj yeem daws tau los ntawm kev siv blockchain thiab los txhawb cov khoom siv, cia peb tsim ib qho me me tab sis tiag tiag blockchain ntawm peb lub vev xaib virtual!
Yog li, cia peb nco ntsoov dab tsi teeb meem blockchain pib daws.
Kuv paub tseeb tias ntau tus yuav hais txog ib qho kev faib tawm, kev faib tawm, pej xeem thiab cov ntaub ntawv tsis hloov pauv. Tab sis vim li cas txhua qhov no tsim nyog?
Kuv xav pib kawm ib qho kev siv tshuab los ntawm kev nyeem cov qauv, txij li tag nrho cov ntawv thiab cov phau ntawv ntawm cov ncauj lus hauv qab no yog raws li lawv. Tab sis tam sim no tsis muaj cov qauv blockchain; ISO tsuas yog tsim pawg neeg rau lawv txoj kev loj hlob. Tam sim no, txhua qhov project blockchain pej xeem muaj nws tus kheej daim ntawv dawb, uas yog qhov tseem ceeb ntawm kev qhia tshwj xeeb. Thawj qhov kev paub txog blockchain project yog Bitcoin network. Mus rau lub vev xaib official ntawm lub network thiab saib qhov twg nws tag nrho pib.
Blockchain Kev Sib Tw
Yog li, txoj haujlwm uas blockchain daws tau hauv Bitcoin pioneer network yog ua kom ntseeg siab hloov pauv ntawm cov tswv cuab ntawm cov cuab yeej cuab tam (cov cuab yeej cuab tam) nyob rau hauv ib puag ncig tsis ntseeg tsis muaj cov neeg nruab nrab. Piv txwv li, hauv Bitcoin network, cov cuab tam digital yog bitcoin digital npib. Thiab tag nrho cov kev daws teeb meem ntawm Bitcoin thiab lwm yam blockchains los daws qhov teeb meem no.
Cov teeb meem uas blockchain daws
Piv txwv tias ib lub koom haum nyiaj txiag hais tias nws tau tsim lub network thoob ntiaj teb nrog kev pab cuam uas nws muaj peev xwm xa nyiaj mus rau txhua tus neeg. Koj puas yuav ntseeg nws? Yog tias lub koom haum no yog Visa lossis MasterCard, feem ntau koj yuav ntseeg nws, tab sis yog, hais lus, AnonymousWorldMoney, tej zaum koj yuav tsis. Vim li cas? Tab sis vim peb paub zoo tias qhov kev faib tawm yog tsim los ntawm cov tuam txhab ntiag tug, rau lub hom phiaj dab tsi, thiab qhov no tuaj yeem ua rau. Cia peb saib ze dua ntawm cov teeb meem ntawm cov tshuab zoo li no thiab lawv yuav daws tau li cas siv blockchain thev naus laus zis.
Cia peb hais tias nyob rau hauv kev cai AnonymousWorldMoney muaj cov servers nrog databases, thiab nws yog qhov zoo yog tias muaj ob peb ntawm lawv hauv cov chaw sib txawv. Thaum tus neeg xa nyiaj hloov pauv nyiaj, kev hloov pauv tau sau npe, uas tau rov ua dua rau txhua tus servers, thiab cov nyiaj mus txog tus neeg txais.
Nyob rau hauv lub ntiaj teb zoo tagnrho, cov tswv yim no ua haujlwm zoo, tab sis hauv peb cov teeb meem hauv qab no tshwm sim:
Yuav ua li cas kom paub tseeb tias tus neeg tau txais kev pab tau txais raws nraim cov nyiaj uas tau pauv mus rau nws? Hais txog kev hais lus, tus xa khoom xa $ 100, thiab tus neeg txais tau txais $ 10. Tus neeg xa tuaj rau AnonymousWorldMoney chaw ua haujlwm nrog nws daim ntawv txais nyiaj, thiab tus neeg ua haujlwm qhia nws cov qauv, qhov twg nws tau sau tias tus neeg xa khoom pauv tsuas yog $ 10.
Qhov teeb meem ntawm ib puag ncig tsis ntseeg, piv txwv li, kev dag ntxias hu ua kev siv nyiaj ob npaug. Ib tus neeg koom nrog uas tsis paub tseeb tuaj yeem siv nws qhov nyiaj tshuav ntau zaus kom txog thaum cov nyiaj them rov qab rau txhua tus servers. CAP Theorem, tau kawg, tsis muaj leej twg tso tseg, thiab qhov kev pom zoo yuav ua tiav thaum kawg, tab sis ib tus neeg yuav tsis tau txais nyiaj rau cov kev pabcuam lossis cov khoom muab. Yog li ntawd, yog tias tsis muaj kev ntseeg siab tag nrho hauv lub koom haum them nyiaj lossis cov koom nrog hauv kev lag luam, ces nws yog qhov tsim nyog los tsim lub network raws li tsis yog kev ntseeg siab, tab sis ntawm cryptography.
Conditional AnonymousWorldMoney muaj tus lej kawg ntawm cov servers uas tuaj yeem ua tsis tau los ntawm kev tsis txhob txwm ua lossis vim muaj kev xav phem.
AnonymousWorldMoney yuav coj nws tus kheej txoj haujlwm pom zoo.
Muaj peev xwm tswj tau. Thaum lub sijhawm ua haujlwm ntawm Bitcoin, nws tau muab tawm tias tib neeg xav tsis tsuas yog hloov pauv cov nyiaj npib rau ib leeg xwb, tab sis kuj tseem saib xyuas ntau yam xwm txheej rau kev hloov pauv, cov xwm txheej ua haujlwm ntawm qhov program, cia li ua cov haujlwm raws li cov xwm txheej, thiab lwm yam.
Yuav ua li cas blockchain daws cov teeb meem no
Kev txheeb xyuas cov neeg tuaj koom yog ua los ntawm kev siv ob lub yuam sij: ntiag tug thiab pej xeem, thiab cov cim kos npe digital cim tshwj xeeb qhia tus neeg xa khoom thiab tus neeg txais, tawm hauv lawv tus kheej tsis qhia npe.
Kev ua lag luam raug sau rau hauv cov blocks, lub hash ntawm lub block yog xam thiab sau rau hauv block tom ntej. Qhov sib lawv liag ntawm kev sau cov hashes hauv blocks muab lub tshuab blockchain nws lub npe, thiab nws kuj ua rau nws tsis tuaj yeem hloov pauv / rho tawm cov blocks lossis ib tus neeg ua lag luam los ntawm cov blocks. Yog li, yog tias ib qho kev lag luam suav nrog hauv blockchain, koj tuaj yeem paub tseeb tias nws cov ntaub ntawv yuav tsis hloov pauv.
Kev dag siv nyiaj ob npaug yog tiv thaiv los ntawm kev ncav cuag qhov kev pom zoo hauv lub network uas cov ntaub ntawv xav tau thiab qhov twg yuav muab pov tseg. Hauv Bitcoin network, kev pom zoo tau ua tiav los ntawm kev ua haujlwm pov thawj (PoW).
Kev ntseeg siab ntawm lub network tau ua tiav los ntawm qhov tseeb tias blockchain yog pej xeem, qhov twg txhua tus neeg koom nrog tuaj yeem khiav lawv tus kheej node, tau txais ib daim ntawv theej tag nrho ntawm blockchain thiab, ntxiv rau, nws tus kheej pib tshawb xyuas kev hloov pauv kom raug. Nws yuav tsum tau muab sau tseg tias niaj hnub blockchains ua rau nws muaj peev xwm tsim tsis tau tsuas yog pej xeem (qhib) tab sis kuj private (kaw) blockchains, raws li zoo raws li kev siv ntawm ua ke schemes.
Lub blockchain yuav tsis tau tshem tawm tag nrho cov commissions, vim hais tias ... koj yuav tsum them cov neeg uas txhawb lub network, tab sis nyob rau hauv lub blockchain qhov kev xav tau rau ib tug commission yog proven li convincingly hais tias tsis muaj kev tsis ntseeg txog nws yuav tsum tau.
Niaj hnub nimno blockchains muaj peev xwm los siv kev lag luam logic, uas hauv blockchain hu ua Smart Contracts. Lub logic ntawm cov ntawv cog lus ntse yog siv rau hauv ntau hom lus siab.
Tom ntej no, peb yuav xav txog cov kev daws teeb meem no kom ntxaws ntxiv.
Blockchain architecture
Blockchain Cheebtsam
Txhua tus neeg tuaj koom tuaj yeem tso lawv tus kheej nrog ib daim ntawv luam ntawm blockchain (tag nrho node). Tag nrho cov nodes uas tuaj yeem sau cov kev lag luam ntawm blockchain hu ua kev pom zoo nodes (pob zeb) los yog miner (miner). Tag nrho cov nodes uas tsuas yog xyuas qhov tseeb ntawm kev hloov pauv yog hu ua audit nodes (kev tshuaj xyuas). Lub teeb cov neeg siv khoom (cov neeg siv lub teeb) tsis khaws tag nrho cov ntawv theej ntawm blockchain, tab sis cuam tshuam nrog lub network siv tag nrho cov nodes.
Cov neeg siv feem ntau siv cov neeg siv lub teeb lossis lub hnab nyiaj hauv lub vev xaib los ua kev lag luam. Tag nrho cov nodes yog txuas rau ib leeg. Nrog cov txheej txheem no, lub network architecture ua kom ruaj khov:
Kev lag luam lub neej voj voog
Cia peb saib ntawm kev lag luam lifecycle thiab rhuav tshem nws los ntawm ib qho:
Txhua qhov kev lag luam blockchain yuav tsum tau kos npe digitally. Yog li ntawd, txhawm rau ua kom tiav kev sib pauv, txhua tus neeg koom yuav tsum muaj ib khub tseem ceeb: ntiag tug / pej xeem. Qee lub sij hawm ib khub ntawm tus yuam sij hu ua lub hnab nyiaj, vim cov yuam sij tsis sib xws nrog tus neeg koom nrog qhov chaw nyob digital thiab qhov sib npaug. Hauv kev muaj tiag, cov yuam sij thiab chaw nyob tsuas yog cov hlua ntawm cov lej hauv cov lej sib txawv. Piv txwv ntawm cov yuam sij thiab lub hnab nyiaj qhov chaw nyob:
Private key: 0a78194a8a893b8baac7c09b6a4a4b4b161b2f80a126cbb79bde231a4567420f
Public key: 0579b478952214d7cddac32ac9dc522c821a4489bc10aac3a81b9d1cd7a92e57ba
Address: 0x3814JnJpGnt5tB2GD1qfKP709W3KbRdfb27V
Txhawm rau tsim cov kos npe digital hauv blockchains, ib qho algorithm raws li elliptic curves yog siv: Elliptic Curve Digital Signature Algorithm (ECDSA). Rau nws ua haujlwm, tus yuam sij ntiag tug (256-ntsis tus lej) feem ntau yog coj los ntawm random. Tus naj npawb ntawm cov kev xaiv tseem ceeb yog 2 rau lub zog ntawm 256, yog li peb tuaj yeem tham txog qhov ua tsis tau zoo ntawm kev sib piv cov txiaj ntsig ntawm tus yuam sij ntiag tug.
Tom ntej no, tus yuam sij pej xeem tau txais los ntawm tus kheej los ntawm kev muab nws cov txiaj ntsig los ntawm kev sib koom ua ke ntawm qhov taw tes nyob rau ntawm qhov nkhaus elliptic, uas ua rau muaj kev sib koom ua ke ntawm qhov taw tes tshiab ntawm tib qhov nkhaus. Qhov kev txiav txim no ua kom koj tau txais ib khub tseem ceeb uas haum rau kev kos npe digitally. Thaum kawg, lub hnab nyiaj qhov chaw nyob yog tshwj xeeb muab los ntawm pej xeem tus yuam sij.
Ua tiav kev nrhiav tus hash yog pov thawj ntawm kev ua haujlwm tiav (Cov Ntawv Pov Thawj Ua Haujlwm, PoW) rau Bitcoin lossis Ethereum tes hauj lwm. Cov txheej txheem ntawm kev nrhiav hashes yog hu ua mining, zoo ib yam li kub mining. Lub npe zoo heev txhais lub ntsiab ntawm cov txheej txheem, vim hais tias muaj kev tshawb nrhiav yooj yim ntawm cov kev xaiv, thiab yog tias ib tug neeg pom ib tus hash haum, ces qhov no yog hmoov tiag. Nws zoo li nrhiav tau qhov kub tiag tiag hauv cov pob zeb pov tseg. Qhov khoom plig thaiv tam sim no yog 12.5 BTC thiab yog tias koj muab nws los ntawm qhov tam sim no Bitcoin tus nqi ntawm $ 3900, koj tau txais ntau tshaj li ib kilogram ntawm kub ntshiab. Muaj ib yam dab tsi los tawm tsam!
Tom qab ua tiav nrhiav tau ib qho hash, qhov thaiv thiab qhov pom hash nws tus kheej raug sau rau hauv blockchain raws li qhov thaiv tom ntej. Ntau cov ntsiab lus ntawm cov qauv ntawm cov blocks tuaj yeem pom hauv kab lus Bitcoin nyob rau hauv ib tug nutshell-Blockchain, thiab hauv qab no yog ib daim duab yooj yim:
Lub blockchain pib nrog ib qho thaiv uas tseem tsis tau muaj qhov hash ntawm lub block dhau los. Muaj tsuas yog ib qho thaiv hauv blockchain thiab nws muaj nws lub npe Chivkeeb thaiv. Cov blocks uas tseem tshuav muaj cov qauv zoo ib yam thiab sib txawv tsuas yog tus lej ntawm kev hloov pauv. Kev lag luam tiag tiag thiab thaiv tam sim no tau tsim hauv Bitcoin lossis Ethereum tuaj yeem saib hauv Thaiv tau saib lawm.
Qhov loj ntawm cov blocks hauv Bitcoin yog txwv rau 1MB thiab nrog tsawg kawg ntawm cov ntaub ntawv hauv kev sib pauv ntawm 200 bytes, qhov siab tshaj plaws ntawm kev hloov pauv hauv ib lub thaiv tuaj yeem yog 6000. Los ntawm no, los ntawm txoj kev, ua raws li qhov kev ua tau zoo ntawm Bitcoin, uas txhua tus neeg luag ntawm: ib qho thaiv tau tsim kwv yees li ib zaug txhua 10 feeb * 60 vib nas this = 600 vib nas this, uas muab kev ua haujlwm zoo txog 10 TPS. Txawm hais tias qhov tseeb, qhov no tsis yog kev tsim khoom, tab sis txhob txwm ua algorithm ntawm kev ua haujlwm. Hauv Ethereum, rau kev sib tw, lawv tsuas yog ua lub sijhawm thaiv lub sijhawm 15 vib nas this. thiab productivity formal soared. Yog li ntawd, nyob rau hauv blockchains uas siv PoW raws li kev pom zoo, nws tsis muaj kev nkag siab los piv kev ua tau zoo ntawm tag nrho, vim nws ncaj qha nyob ntawm qhov nyuaj ntawm kev xam cache, uas tuaj yeem muab rau txhua tus nqi.
Forks
Yuav ua li cas yog hais tias, piv txwv li, ob peb nodes pom hashes uas ua tau raws li cov complexity tej yam kev mob, tab sis txawv nyob rau hauv tus nqi (nyob rau hauv lwm yam lus, lawv tuaj rau txawv consensuses) thiab sau ntawv blocks rau lub blockchain? Cia peb saib yuav ua li cas blockchain tiv thaiv qhov xwm txheej no. Nyob rau hauv cov ntaub ntawv no, ib tug thiaj li hu ua rab rawg tshwm sim, thiab lub blockchain muaj ob versions ntawm cov saw:
Yuav ua li cas ntxiv? Tom ntej no, ib feem ntawm lub network pib ua haujlwm ntawm thaiv N + 2 los ntawm ib txoj saw, thiab ib feem ntawm lwm qhov:
Ib qho ntawm cov blocks no yuav pom ua ntej thiab xa mus rau blockchain, thiab tom qab ntawd, raws li txoj cai, blockchain yuav tsum hloov mus rau cov saw ntev dua thiab tshem tawm tag nrho cov kev lag luam los ntawm lwm qhov thaiv:
Nyob rau tib lub sijhawm, qhov xwm txheej yuav tshwm sim thaum tus neeg koom nrog kev sib pauv tsuas yog hauv ib qho ntawm rab rawg blocks, uas tau muab tso tseg. Yog li ntawd, kom paub tseeb tias qhov xav tau kev hloov pauv tau sau tseg hauv blockchain, muaj cov lus pom zoo dav dav - ua ntej tso siab rau kev hloov pauv, koj yuav tsum tos kom txog thaum ob peb ntu ntxiv ntxiv rau blockchain. Cov lus pom zoo kom muaj pes tsawg blocks tos rau qhov sib txawv blockchains sib txawv. Piv txwv li, rau Bitcoin network qhov tsawg kawg nkaus yog 2 blocks, qhov siab tshaj plaws yog 6.
Tib daim duab nrog thaiv rab rawg yuav raug soj ntsuam thaum lub sijhawm hu ua 51% nres - qhov no yog thaum ib pab pawg neeg miners sim loj hlob lwm txoj hlua thaiv, nrhiav kev tshem tawm cov saw nrog lawv cov kev dag ntxias. Txawm hais tias tam sim no, es tsis txhob dag, nws muaj txiaj ntsig ntau dua los siv koj lub zog ntawm kev ncaj ncees mining.
Kev pom zoo
Txhawm rau sau ib qho thaiv ntawm blockchain, lub network yuav tsum ncav cuag qhov kev pom zoo. Cia peb nco qab txog txoj haujlwm ntawm kev ua tiav kev pom zoo hauv kev sib txuas lus hauv computer. Qhov teeb meem yog tsim raws li txoj haujlwm ntawm Byzantine generals BFT (Lub txim txhaum Byzantine). Omitting cov lus piav qhia zoo nkauj ntawm cov teeb meem ntawm cov tub rog Byzantine, qhov teeb meem tuaj yeem tsim tau raws li hauv qab no: yuav ua li cas lub network nodes tuaj yeem tshwm sim yog tias qee lub network nodes tuaj yeem txhob txwm cuam tshuam lawv. Cov algorithms uas twb muaj lawm los daws qhov teeb meem BFT qhia tau tias lub network tuaj yeem ua haujlwm raug yog tias muaj tsawg dua 1/3 cov neeg dag. Vim li cas ho tsis tau pom zoo BFT tau thov rau Bitcoin network? Vim li cas thiaj tsim nyog siv PoW? Muaj ntau yam laj thawj:
BFT ua haujlwm zoo nrog cov txheej txheem me me ntawm cov nodes, tab sis nyob rau hauv pej xeem blockchain tus naj npawb ntawm cov nodes yog unpredictable thiab, ntxiv rau, cov nodes tuaj yeem qhib thiab tawm tsis tau.
Nws yog ib qho tsim nyog los txhawb cov neeg los tsim cov blockchain nodes. Ua li no, tib neeg yuav tsum tau txais nqi zog. Hauv BFT tsis muaj ib yam dab tsi uas yuav tau txais txiaj ntsig rau, tab sis qhov khoom plig yog dab tsi rau hauv PoW yog qhov tseeb rau txhua tus neeg ntawm qhov kev nkag siab zoo: rau cov hluav taws xob siv los ntawm processor hauv cov txheej txheem ntawm kev nrhiav cov block hash.
Kev ntseeg tau thiab xa tawm qauv ntawm blockchains
Public blockchain
Sustainability Public los yog lwm lub npe Txwv tsis pub blockchain Qhov no yog ua tiav los ntawm kev tso cai rau leej twg los txuas thiab saib cov ntaub ntawv lossis txawm txuas lawv tus kheej, thiab kev ntseeg siab tau tsim los ntawm PoW kev pom zoo.
Private blockchain
private los yog Private Permissioned blockchain. Hauv cov blockchains no, tsuas yog ib pawg neeg koom nrog (cov koom haum lossis tib neeg) tau nkag mus rau cov ntaub ntawv. Xws li blockchains yog tsim los ntawm cov koom haum nrog lub hom phiaj ntawm kev nce cov txiaj ntsig tag nrho lossis kev ua tau zoo. Lawv qhov kev ntseeg tau raug lees paub los ntawm cov hom phiaj ntawm cov neeg koom nrog thiab PoS thiab BFT kev pom zoo algorithms.
Blockchain Consortium
Muaj ntau Kev Sib Raug Zoo los yog Public Permissioned blockchain. Cov no yog cov blockchains uas leej twg tuaj yeem txuas mus saib, tab sis tus neeg koom tuaj yeem ntxiv cov ntaub ntawv lossis txuas nws cov node nkaus xwb nrog kev tso cai los ntawm lwm tus neeg koom. Xws li blockchains yog tsim los ntawm cov koom haum txhawm rau ua kom muaj kev ntseeg siab ntawm ib feem ntawm cov neeg siv khoom lossis cov neeg siv khoom ntawm cov khoom lossis tib neeg tag nrho. Ntawm no, kev ntseeg siab kuj tau ua tiav los ntawm kev muaj kev ntseeg siab ntawm cov neeg koom thiab tib lub PoS thiab BFT kev pom zoo algorithms.
Ntse Contracts
Blockchains tau siv tom qab Bitcoin muaj, rau ib qib lossis lwm qhov, ntxiv lub peev xwm los ua cov ntawv cog lus ntse. Qhov tseem ceeb, daim ntawv cog lus ntse yog kev lag luam uas qhov program code muab tso rau kev ua tiav. Cov ntawv cog lus ntse ntawm Ethereum network tau ua tiav hauv EVM (Ethereum Virtual Machine). Txhawm rau pib ua tiav daim ntawv cog lus ntse, nws yuav tsum tau tshaj tawm los ntawm lwm qhov kev sib pauv, lossis cov xwm txheej ua ntej rau kev ua tiav yuav tsum tau ua tiav. Cov txiaj ntsig ntawm kev ua tiav ntawm daim ntawv cog lus ntse tseem yuav raug kaw hauv blockchain. Tau txais cov ntaub ntawv los ntawm sab nraud blockchain yog ua tau, tab sis tsis tshua muaj kev txwv.
Dab tsi ua lag luam logic tuaj yeem siv tau siv daim ntawv cog lus ntse? Qhov tseeb, tsis muaj ntau, piv txwv li, tshawb xyuas cov xwm txheej siv cov ntaub ntawv los ntawm blockchain, hloov cov tswv ntawm cov cuab tam digital nyob ntawm cov xwm txheej no, sau cov ntaub ntawv hauv ib qho chaw ruaj khov hauv blockchain. Lub logic yog siv nyob rau hauv ib tug tshwj xeeb high-level lus Solidity.
Ib qho piv txwv classic ntawm kev ua haujlwm uas tau siv los siv cov ntawv cog lus ntse yog muab cov tokens rau ICOs. Piv txwv li, kuv tau siv daim ntawv cog lus ntse los muab 500 AlexToken. Los ntawm txuas hauv Etherscan yog nyob
pragma solidity ^0.4.23;
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
**/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
**/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
**/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
**/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
}
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
**/
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender account.
**/
constructor() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
**/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
**/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
/**
* @title ERC20Basic interface
* @dev Basic ERC20 interface
**/
contract ERC20Basic {
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
**/
contract ERC20 is ERC20Basic {
function allowance(address owner, address spender) public view returns (uint256);
function transferFrom(address from, address to, uint256 value) public returns (bool);
function approve(address spender, uint256 value) public returns (bool);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
**/
contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
**/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
**/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
**/
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
}
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
**/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
**/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
**/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
**/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
**/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
}
/**
* @title Configurable
* @dev Configurable varriables of the contract
**/
contract Configurable {
uint256 public constant cap = 1000000000*10**18;
uint256 public constant basePrice = 100*10**18; // tokens per 1 ether
uint256 public tokensSold = 0;
uint256 public constant tokenReserve = 500000000*10**18;
uint256 public remainingTokens = 0;
}
/**
* @title CrowdsaleToken
* @dev Contract to preform crowd sale with token
**/
contract CrowdsaleToken is StandardToken, Configurable, Ownable {
/**
* @dev enum of current crowd sale state
**/
enum Stages {
none,
icoStart,
icoEnd
}
Stages currentStage;
/**
* @dev constructor of CrowdsaleToken
**/
constructor() public {
currentStage = Stages.none;
balances[owner] = balances[owner].add(tokenReserve);
totalSupply_ = totalSupply_.add(tokenReserve);
remainingTokens = cap;
emit Transfer(address(this), owner, tokenReserve);
}
/**
* @dev fallback function to send ether to for Crowd sale
**/
function () public payable {
require(currentStage == Stages.icoStart);
require(msg.value > 0);
require(remainingTokens > 0);
uint256 weiAmount = msg.value; // Calculate tokens to sell
uint256 tokens = weiAmount.mul(basePrice).div(1 ether);
uint256 returnWei = 0;
if(tokensSold.add(tokens) > cap){
uint256 newTokens = cap.sub(tokensSold);
uint256 newWei = newTokens.div(basePrice).mul(1 ether);
returnWei = weiAmount.sub(newWei);
weiAmount = newWei;
tokens = newTokens;
}
tokensSold = tokensSold.add(tokens); // Increment raised amount
remainingTokens = cap.sub(tokensSold);
if(returnWei > 0){
msg.sender.transfer(returnWei);
emit Transfer(address(this), msg.sender, returnWei);
}
balances[msg.sender] = balances[msg.sender].add(tokens);
emit Transfer(address(this), msg.sender, tokens);
totalSupply_ = totalSupply_.add(tokens);
owner.transfer(weiAmount);// Send money to owner
}
/**
* @dev startIco starts the public ICO
**/
function startIco() public onlyOwner {
require(currentStage != Stages.icoEnd);
currentStage = Stages.icoStart;
}
/**
* @dev endIco closes down the ICO
**/
function endIco() internal {
currentStage = Stages.icoEnd;
// Transfer any remaining tokens
if(remainingTokens > 0)
balances[owner] = balances[owner].add(remainingTokens);
// transfer any remaining ETH balance in the contract to the owner
owner.transfer(address(this).balance);
}
/**
* @dev finalizeIco closes down the ICO and sets needed varriables
**/
function finalizeIco() public onlyOwner {
require(currentStage != Stages.icoEnd);
endIco();
}
}
/**
* @title LavevelToken
* @dev Contract to create the Lavevel Token
**/
contract AlexToken is CrowdsaleToken {
string public constant name = "AlexToken";
string public constant symbol = "ALT";
uint32 public constant decimals = 18;
}
thiab tus sawv cev binary raws li lub network pom nws
Peb tau teev cov thev naus laus zis uas niaj hnub blockchains tau tsim thiab lawv txuas rau ib leeg li cas. Tam sim no cia peb tsim cov teeb meem twg tuaj yeem daws tau siv blockchain, thiab cov kev daws teeb meem twg yuav, qhov zoo tshaj plaws, tsis muaj txiaj ntsig. Yog li, siv blockchain tsis tsim nyog yog tias:
Kev ua lag luam tau ua nyob rau hauv ib puag ncig kev ntseeg siab;
Lub xub ntiag ntawm ib tug commission ntawm intermediaries tsis ua phem rau lub neej ntawm cov neeg koom;
Cov neeg koom tsis muaj cov cuab yeej uas tuaj yeem sawv cev ua cov cuab tam digital;
Tsis muaj kev faib tawm hauv cov cuab tam digital, i.e. tus nqi yog tus tswv lossis muab los ntawm tsuas yog ib tus neeg koom nrog.
Dab tsi yav tom ntej tuav rau blockchain? Tam sim no peb tsuas tuaj yeem kwv yees txog txoj hauv kev ua tau rau kev txhim kho ntawm blockchain technologies:
Blockchain yuav dhau los ua tib yam kev siv tshuab database xws li, piv txwv li, SQL lossis NoSQL rau kev daws nws cov teeb meem tshwj xeeb;
Blockchain yuav dhau los ua cov txheej txheem dav dav, zoo li HTTP yog rau Is Taws Nem;
Blockchain yuav dhau los ua lub hauv paus rau qhov tshiab nyiaj txiag thiab kev nom kev tswv hauv ntiaj teb!
Hauv ntu tom ntej peb yuav saib seb blockchains tam sim no muaj dab tsi thiab vim li cas lawv thiaj siv hauv kev lag luam sib txawv.