Iyi ngingo ntabwo yerekeranye no gukoresha amafaranga cyangwa kwegereza ubuyobozi abaturage. Ahubwo, tuzasesengura imbuga rusange za EVM nuburyo zishobora gukoreshwa mumushinga wawe utaha, ukurikije ibyo ukeneye n'intego zawe. Nzibira mubyiza, ibibi, nurugero rufatika, nkoresheje isomero rya 0xweb nakoraga.
Byarangije gukora. Sobanura gusa icyitegererezo cyamakuru yawe nkamasezerano hanyuma uyakoreshe.
Amakuru yawe amaze gushyirwaho, irakomeza kuboneka mugihe cyose blocain ikora. Ndashobora kwibwira ko bizaba birebire cyane kurenza abandi biyandikishije.
Gutandukanya gusoma no kwandika muburyo bwo guhagarika byerekana 100% igihe cyo gukora ibikorwa byo gusoma, cyane cyane iyo ukoresha abatanga RPC benshi kugirango barengere.
Blockchains isanzwe itanga urwego rwo hejuru rwumutekano kuruta ibisanzwe byakirwa. Gukoresha amakuru birashoboka gusa mugihe intege nke zibaho muri logique yamakuru yawe.
Keretse niba uhishe, amakuru yawe akomeza gufungura, kugerwaho, no kugenzurwa numuntu uwo ari we wese, biteza imbere gukorera mu mucyo.
Amazina ya domaine ntabwo akenewe kubwubu bwoko bwinyuma. Ahubwo, urutonde rwabegerejwe abaturage batanga node irashobora gukoreshwa, kwemerera amasomero yabakiriya guhitamo amahitamo meza kubakoresha-nyuma.
Turashimira kubiranga hejuru, inyuma-yinyuma-yinyuma yubaka kubakoresha mukwizera umutekano wamakuru no 24/7 kuboneka, nubwo kubungabunga imishinga niterambere bihagarara.
Urashobora guhuza izindi moderi zamakuru zabitswe kuri blocain, cyangwa indi mishinga irashobora gushingira kumiterere yamakuru yawe.
Abakoresha barashobora gukoresha imishinga myinshi-y-igice kugirango bakurikirane cyangwa bahindure ibikorwa, bagure cyane ibishoboka byerekana amakuru yawe.
Amakuru arashobora kuboneka kuva aho ariho hose kera.
Ongeramo ibintu byabigenewe byamateka cyangwa ukoreshe WebSockets kugirango wumve ibihe nyabyo byinjira, bigushoboza ibisubizo byingirakamaro.
Igitekerezo cya "ikotomoni" gifasha abakoresha kwimenyekanisha ubwabo basinya ubutumwa, batanga imenyekanisha ryabakoresha badafite ikinyabupfura.
Abakoresha barashobora guhindura cyangwa kwagura amakuru mububiko bwawe ukurikije uruhushya usobanura. Icyangombwa, ibiciro byibi byahinduwe bitangwa nabakoresha ubwabo. Muguhitamo ibiciro bidahenze, aya mafaranga arashobora kuguma ari ntarengwa, akenshi agera kumafaranga make kuri buri gikorwa.
Nubwo ikurikiza uburyo bwukuri bwo kwishyura-nkuko ugenda, wishyura gusa SLOTs ubitse. Buri SLOT ifite 32 bytes, bisaba GAS 20000 kwandika amakuru mashya cyangwa 5000 GAS kugirango ivugurure amakuru. Reka dufate urugero rwa Polygon, hamwe nigiciro cya 30-gwei GAS nigiciro cya $ 0.60 POL.
20000GAS × 30gwei = 0.008 POL × $ 0.60 = $ 0.00032
Ibi nibyinshi, so "Floppy Disk" emoji yerekana umubare wububiko muburyo bwiza, bivuze ko bikwiranye na datasets nto niba wishyuye wenyine. Nyamara, inyungu idasanzwe nuko abakoresha bashobora kwishura ikiguzi cyububiko bwabo nibikorwa byabo, ibintu bitabonetse mubindi buhanga. Mugihe ubu buryo bushobora kubangamira iyakirwa rya porogaramu yawe, biremewe cyane mumuryango uhagarika.
Guhagarika amakuru yerekana amakuru ashyigikira imikorere yo guhuza amakuru, ariko ubushobozi bwabo bwo kubara bufite imbogamizi. Izi mbogamizi ziterwa na node ya RPC ukoresha mugusoma ibikorwa hamwe nimbibi zikomeye za GAS zashyizweho kubikorwa byo kwandika (transaction). Mugihe ibikorwa byibanze, ibizunguruka, hamwe nimbaraga zihamagara zisanzwe zishobora gucungwa, guhagarika ntibikwiranye numurimo uremereye wo kubara.
Ibyo byavuzwe, ukurikije ingano ntoya yamakuru asanzwe arimo, imipaka ihari mubisanzwe irahagije kubibazo byinshi byakoreshejwe.
Niba uri mushya kugirango uhagarike iterambere, ushobora kuba warumvise ko bigoye kandi bigoye gutangira. Ariko, ibi ntabwo arukuri. Iterambere rya Blockchain rikoresha ibitekerezo bisanzwe, ibisobanuro, hamwe na syntax, byoroshye kwiga kuruta uko bigaragara.
https://github.com/0xweb-org/urugero-inyuma
Kubwiyi ngingo, reka dushyireho verisiyo yubuyobozi bwa kontaro. Tekereza ufite porogaramu ya desktop isaba inyuma kugirango igenzure verisiyo nshya no kugarura imiyoboro yo gukuramo igihe cyose verisiyo nshya isohotse. Hasi ni amasezerano yanyuma, yerekana byinshi mubyingenzi:
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; struct Package { uint version; uint timestamp; string url; bytes32 sha256; } contract AppVersionManager is Ownable { // Events that are emitted on data updates event NewApplicationInfo(); event NewPackage(uint version, uint timestamp); // Custom error, when title for the application is empty error TitleIsEmpty(); // Some application information string public title; // @TODO: add further application related properties if required // Latest package Package public package; // Track all versions and their packages mapping (uint => Package) public packages; // List of all previous versions uint[] public versions; constructor () Ownable(msg.sender) { } function updateInfo(string calldata newTitle) external onlyOwner { if (bytes(newTitle).length == 0) { revert TitleIsEmpty(); } title = newTitle; emit NewApplicationInfo(); } function updatePackage(Package calldata newPackage) external onlyOwner { require(newPackage.version > package.version, "Newer package already published"); packages[package.version] = package; package = newPackage; versions.push(package.version); emit NewPackage(package.version, block.timestamp); } function findPackageAtTimestamp (uint timestamp) external view returns (Package memory) { if (package.timestamp <= timestamp) { return package; } // the countdown loop to find the latest package for the timestamp int i = int(versions.length); while (--i > -1) { Package memory pkg = packages[versions[uint(i)]]; if (pkg.timestamp <= timestamp) { return pkg; } } revert("No package found"); } function getPackage (uint version) external view returns (Package memory) { if (version == package.version) { return package; } return packages[version]; } }
Buri muterimbere arashobora gusoma no gusobanukirwa iyi code nimbaraga nke. Niba umenyereye TypeScript, ibyinshi mubitekerezo hano bizaba bimaze kumvikana. Kugirango birusheho gusobanuka, Nashizeho urugero rwa TypeScript ingero: AppVersionManager.ts 🔗 .
Mumagambo yoroshye, amasezerano muri Solidity arashobora gutekerezwa nkurugero rwicyiciro cya leta . Ibitekerezo byumutungo, uburyo, ubwoko, numurage bimaze kumenyekana cyane mubikorwa-bigamije gahunda. Igitekerezo nyamukuru cyo gusobanura hano nicyo onlyOwner
cyo guhindura ibintu (bisa nuwishushanya muri TypeScript).
Buri konte yo guhagarika ni mubyukuri urufunguzo rwigenga nurufunguzo rusange. Indangamuntu ya konti, izwi nka aderesi , ikomoka ku rufunguzo rusange. Iyo transaction ikozwe, aderesi yohereje inyuzwa nka msg.sender
. Ukoresheje ibi, turashobora kubika adresse yawe mubwubatsi (mugihe cyo kohereza amasezerano). Nyuma, moderi onlyOwner
yemeza ko wowe wenyine, nka nyiri amasezerano, ushobora gukora updateInfo
no kuvugurura imikorere updatePackage
. Niba hari undi ugerageje ibyo bikorwa, transaction izagaruka. Impinduka onlyOwner
itangwa namasezerano Ownable
, akaba ari mubitabo bikoreshwa cyane mubitabo bya OpenZeppelin . Iri somero ririmo andi masezerano menshi yingirakamaro kugirango yorohereze iterambere.
Indi ngingo y'ingenzi yo kuganiraho ni igitekerezo cya Proxies , igabanya ububiko nogushyira mubikorwa mumasezerano abiri atandukanye. Gushyira mu bikorwa amasezerano muri Solidity ntibihinduka, bivuze ko udashobora kongera imirimo mishya cyangwa imitungo nyuma yo koherezwa. Kugirango ukore hafi yibi, urashobora kohereza amasezerano "Proxy". Porokireri ikora ububiko kandi ikubiyemo imikorere imwe fallback
, ihamagarira guhamagarira amasezerano yo kuyashyira mubikorwa mugihe ikomeza ububiko bwa Proxy.
Iki gitekerezo gishobora kumvikana, ariko birasa nuburyo this
bikora muri JavaScript. Dore ikigereranyo cyihuse cyo gufasha gusobanura:
const foo = new Proxy({ bar: 'Lorem' }, { get (obj, prop) { return fooImplementation[prop].bind(obj) }, }); const fooImplementation = { logValue () { console.log('Bar value:', this.bar) } } foo.logValue();
Amasezerano ya porokisi afite aho yerekeza ku masezerano yo kuyashyira mu bikorwa. Niba ushaka kongeramo imirimo mishya, urakoresha gusa amasezerano mashya yo gushyira mubikorwa no kuvugurura proksi kugirango yerekane aya masezerano mashya, wohereze imikorere ihamagarwa kurugero ruvuguruwe. Nibikorwa byoroshye, ariko hariho urubanza rwo gusuzuma: abubaka.
Iyo ukoresheje amasezerano yo kuyashyira mubikorwa, uyubaka akorera mububiko bwamasezerano ubwayo. Ibi bivuze ko abashiraho nka title = "Hello World"
ntibazahindura ububiko bwa proxy. Kugira ngo iki kibazo gikemuke, dukoresha igitekerezo cyo gutangiza ibikorwa :
initialize
.initialize
kwitwa murwego rwamasezerano ya proxy.
Nkigisubizo, kuvugurura imitungo title
, kurugero, izavugurura neza mububiko bwa porokisi.
Dore verisiyo yo kuzamura ishyirwa mubikorwa rya AppVersionManager: AppVersionManagerUpgradeable.sol .
Amasezerano ya porokisi ubwayo ni rusange kandi yigenga kubishyira mubikorwa. Ibipimo byinshi bizwi kuri proksi birahari mubitabo bya OpenZeppelin.
Hamwe n'ubumenyi bw'ibi bitekerezo hamwe n'ingero zavuzwe haruguru, uriteguye guteza imbere amasezerano yubwenge kubibazo byawe.
Ubwa mbere, dukeneye guhitamo blocain aho dushaka kohereza amasezerano. Kurugero, Nahisemo Polygon. Itanga amafaranga make yo gucuruza, yabayeho kuva kera, kandi ikora neza. Ibikorwa remezo bihamye kandi bikora neza, bifatanije nigiciro cyuzuye gifunze (TVL) cya miliyari 0.9 z'amadolari, bituma ihitamo neza. Kohereza amasezerano yawe kumurongo rusange bisobanura kubana nibigo byimari. Ibipimo bya TVL byerekana ikizere ibyo bigo bitanga muburyo bwo kwizerwa.
Byongeye kandi, niba ibintu bihindutse, urashobora guhora wohereza amasezerano kurindi zindi mugihe kizaza.
Umushinga wa demo ukora kandi nkububiko bwa CI ibizamini, bityo amategeko yose murayasanga hano: https://github.com/0xweb-org/urugero-bisubiza/blob/master/deploy-cli.sh
# Install 0xweb library from NPM into the prject folder npm i 0xweb # Install required dependencies to compile/deploy *.sol files npx 0xweb init --hardhat --openzeppelin # Create or import the account. Private key will be encrypted with pin AND machine key. npx 0xweb accounts new --name foo --pin test --login # Save the private key securly and ensure the account has some POL tokens # Deploy. The foo account is selected as default. npx 0xweb deploy ./contracts/AppVersionManager.sol --chain polygon --pin test # Set title npx 0xweb c write AppVersionManager updateInfo --newTitle MySuperApp --pin test # Set latest package information npx 0xweb c write AppVersionManager updatePackage --arg0 'load(./data/package.json)' --pin test
Hamwe namabwiriza make, wohereje amasezerano kandi uvugurura amakuru. Nibyo kuri inyuma - ubu irazamuka kandi ikora "iteka" udakeneye ikindi gikorwa kiva kuruhande rwawe. Amafaranga yo koherezwa, ku giciro cya GAS 70 gwei nigiciro cya POL $ 0.51, cyaba:
| GAS | POL | $ |
---|---|---|---|
Kohereza | 850352 | 0.059 | 0.03 |
Bika Umutwe | 47517 | 0.0033 | 0.001 |
Bika Amapaki | 169549 | 0.0118 | 0.006 |
Igiteranyo | | | 0.037 |
Ukoresha amafaranga 4 gusa kugirango ushireho serivisi zegerejwe abaturage , umutekano , kandi uramba- ntagikorwa gisabwa.
Kubaza amakuru yawe yamasezerano, uzakenera abatanga node ya RPC. Abatanga ibicuruzwa byinshi baraboneka kuri https://chainlist.org . Urashobora guhitamo abatanga ibintu byinshi, kandi isomero ryiza rya Web3 rirashobora gukoresha ingamba zizenguruka mugihe cyo guhitamo icyiza kubakoresha amaherezo. Hamwe na 0xweb, ibyakozwe na TypeScript cyangwa JavaScript ibyiciro ntabwo bihitamo gusa impera nziza ahubwo binakuraho itumanaho ryose. Abakiriya barimo uburyo bwo murwego rwohejuru rwo kuzana amakuru, bigatuma inzira idahwitse kandi neza.
# The deploy command also generates the class, but manual install is also possible npx 0xweb i 0x<address> --name AppVersionManager --chain polygon
import { AppVersionManager } from './0xc/polygon/AppVersionManager/AppVersionManager' const manager = new AppVersionManager(); console.log(`Title`, await manager.title()); console.log(`Package`, await manager.package());
Ku zindi ndimi za porogaramu, hariho amasomero menshi aboneka kugirango yoroshye kubaza ikibazo. Nyuma yo koherezwa, uzagira aderesi yamasezerano na ABI (interineti).
Ubundi, urashobora gutangiza seriveri yo hagati kugirango ubaze amakuru yamasezerano ukoresheje 0xweb.
npx 0xweb server start --port 3000 curl http://localhost:3000/api/c/read/AppVersionManager/package?chain=polygon
Inyungu imwe nuko udakeneye gushyiramo amasomero ayo ari yo yose - ibyifuzo bya HTTP mbisi. Nyamara, ubu buryo bushingiye kuri seriveri yinyongera uzakenera kuyobora. Nibyiza cyane kubaza blocain ukoresheje amasomo ya 0xweb yakozwe cyangwa andi masomero yo guhagarika arahari.
Iyi ngingo yerekanye uburyo blocain ishobora kuba yoroshye kandi ikomeye, itanga inyungu zidasanzwe ugereranije nibisanzwe byakirwa.
Mu kiganiro gikurikira, ndateganya gushakisha imiyoboro yabitswe ya BLOB yegerejwe abaturage nka Greenfield na Arweave, nkagaragaza ibiranga inyungu zabo.
Niba ufite igitekerezo cyangwa igitekerezo cyinyongera kugirango ushire mubitabo 0xweb, wumve neza kubisangiza mubitekerezo cyangwa ugere kuri [email protected] .