paint-brush
Ngaba ukuphuhlisa iBlockchain njenge-Backend ngokwenene yonke into enzima?nge@0xtnbts
Imbali entsha

Ngaba ukuphuhlisa iBlockchain njenge-Backend ngokwenene yonke into enzima?

nge Alex Kit11m2025/01/17
Read on Terminal Reader

Inde kakhulu; Ukufunda

Eli nqaku alikho malunga ne-cryptocurrency okanye i-decentralized finance. Endaweni yoko, siza kuphonononga iibhloko ze-EVM zoluntu kunye nokuba zingasetyenziswa njani kwiprojekthi yakho elandelayo. Ndiza kuphonononga izinto ezilungileyo, ezimbi, kunye nemizekelo ebonakalayo, ndisebenzisa ithala leencwadi le-0xweb.
featured image - Ngaba ukuphuhlisa iBlockchain njenge-Backend ngokwenene yonke into enzima?
Alex Kit HackerNoon profile picture

Eli nqaku alithethi malunga ne-cryptocurrency okanye i-decentralized finance. Endaweni yoko, siza kuphonononga iibhloko ze-EVM zoluntu kunye nokuba zingasetyenziswa njani kwiprojekthi yakho elandelayo, kuxhomekeke kwiimfuno zakho kunye neenjongo. Ndizakuntywila kwizinto ezilungileyo, ezimbi, kunye nemizekelo ebonakalayo, ndisebenzisa ithala leencwadi le -0xweb ebendisebenza kulo.

§ pro et contra

• 🚀 Zero ukuseta ixesha

Sele iphezulu kwaye isebenza. Chaza ngokulula imodeli yakho yedatha njengekhontrakthi kwaye uyisebenzise.

• ✨ Ukugcinwa kweqanda

Nje ukuba idatha yakho ilayishwe, ihlala ifikeleleka logama nje i-blockchain isebenza. Ndinokucinga ukuba iya kuba yinde kakhulu kunomnye umrhumo wakho wokubamba.

• 💯 100% Funda ixesha lokuphumla; kufutshane ne-100% Bhala ixesha lokuphumla

Ukwahlulwa kweenkqubo zokufunda nokubhala kwi-blockchain iqinisekisa i-100% yokuphumla kwimisebenzi yokufunda, ngakumbi xa kuxhatshazwa ababoneleli abaninzi be-RPC yokuphindaphinda.

• 🛡️ Khusela

IiBlockchains ngokwemvelo zibonelela ngenqanaba eliphezulu lokhuseleko kunezisombululo zokubamba eziqhelekileyo. Ukusetyenziswa kwedatha kunokwenzeka kuphela ukuba ubuthathaka bukhona kwingqiqo yemodeli yakho yedatha.

• 📖 Vula iDatha

Ngaphandle kokuba iguqulelwe ngokuntsonkothileyo, idatha yakho ihlala ivuliwe, ifikeleleka kwaye iqinisekiswa nguye nabani na, ikhuthaza ukungafihli.

• 🖧 DNS-Mahala

Amagama e-Domain awafuneki kolu hlobo lwe-backend. Endaweni yoko, uluhlu lwababoneleli beendawo ezinatyisiweyo lunokusetyenziswa, luvumela iilayibrari zabaxumi ukuba zikhethe eyona ndlela isebenzayo kubasebenzisi bokugqibela.

• 🤝 Thembela

Ndiyabulela kwiimpawu ezingentla, i-blockchain-based backends ngokwemvelo yakha ukuthembela komsebenzisi ngokuqinisekisa ukhuseleko lwedatha kunye nokufumaneka kwe-24/7, nokuba ukugcinwa kweprojekthi kunye nophuhliso luyayeka.

• 🧩 Ukuba nomdla kwimodeli yedatha yomntu wesithathu

Unokudibanisa ezinye iimodeli zedatha ezigcinwe kwi-blockchain, okanye ezinye iiprojekthi ezinokwakha phezu kwemodeli yakho yedatha.

• ⚙️ Ukwandiswa

Abasebenzisi banokunyusa iiprojekthi ezininzi zeqela lesithathu ukubeka iliso okanye ukwenza ngokuzenzekelayo izenzo, ukwandisa ngokubalulekileyo amathuba emodeli yakho yedatha.

• 📜 Imbali kunye nexesha lokuhamba

Idatha inokufumaneka kuyo nayiphi na indawo kwixesha elidlulileyo.

• 📡 Imisitho kunye neminyhadala yemisitho

Layisha iziganeko zesithethe zembali okanye usebenzise iiWebSockets ukumamela iziganeko zexesha langempela ezingenayo, uvumela iimpendulo zezicelo ezinamandla.

• 👤 Isazisi somsebenzisi esakhelwe ngaphakathi

Ingqikelelo "ye-wallet" yenza ukuba abasebenzisi baziqinisekise ngokusayina imiyalezo, babonelele ngokungenamthungo kunye nokuchongwa kwabasebenzisi.

• 📝 Nika abasebenzisi ukuguqula okanye ukwandisa idatha

Abasebenzisi banokuguqula okanye bandise idatha kwindawo yakho yokugcina ngokusekelwe kwiimvume ozichazayo. Okubalulekileyo, iindleko zolu hlengahlengiso zithwalwa ngabasebenzisi ngokwabo. Ngokukhetha i-blockchain enexabiso eliphantsi, ezi ntlawulo zihlala zingahoywa, zihlala zifikelela kuphela kwiisenti ezimbalwa kwintengiselwano nganye.

• 🌐 Enkulu kwaye iqhubeka nokuvela kwinkqubo yendalo

  • iimodyuli ezininzi zokuqina onokuzisebenzisa ukuphucula ukusebenza kwemodeli yakho yedatha.
  • iinkonzo ezininzi ezivulekileyo kunye nezasimahla, kunye nezo zibonelela ngezicwangciso zasimahla, ziyafumaneka. Yinto eqhelekileyo ngaphakathi kuluntu lwe-blockchain ukubonelela ngezicwangciso zamahhala ezihlala zanele kwiimfuno zemveliso.

§ ngokuchaseneyo

• 💾 Ukugcinwa kuyabiza 😢

Nangona ilandela imodeli yokuhlawula yokwenyani, uhlawula nje ii-SLOTs ogcina kuzo. I-SLOT nganye ine-bytes ezingama-32, kubiza i-20000 GAS ukubhala idatha entsha okanye i-5000 GAS ukuhlaziya idatha. Makhe sithathe iPolygon njengomzekelo, ngexabiso le-GAS ye-30-gwei kunye nexabiso le-0.60 POL.


20000GAS × 30gwei = 0.008 POL × $0.60 = $0.00032


Oku kuninzi, ke i-emoji ethi "Floppy Disk" imele izixa zokugcina ngeyona ndlela ingcono, okuthetha ukuba ifaneleke kakhulu kwiiseti zedatha ezincinci ukuba uhlawula ngokwakho. Nangona kunjalo, inzuzo ekhethekileyo kukuba abasebenzisi banokuthwala iindleko zokugcina kunye nezenzo zabo, into engafumanekiyo kwezinye iiteknoloji. Ngelixa le ndlela inokuthintela ukwamkelwa kobuninzi be-app yakho, yamkelwe ngokubanzi kuluntu lwe-blockchain.

• 🧮 Ukubala kulinganiselwe 😢

Iimodeli zedatha yeBlockchain zixhasa imisebenzi yokusebenzisana neenkcukacha, kodwa amandla abo okubala anemiqobo. Le mida ixhomekeke kwii-RPC nodes ozisebenzisela iintshukumo zokufunda kunye nemida engqongqo ye-GAS ebekwe kwiintshukumo zokubhala (intengiselwano). Ngelixa imisebenzi esisiseko, iilophu, kunye nenqwaba yeefowuni ezinzulu zilawuleka, ibhloko ayilufanelanga umthwalo onzima wokubala.


Oko kuthethiweyo, xa kujongwa ubungakanani bedatha encinci ngokwentelekiso ebandakanyekayo, imida ekhoyo ihlala yanele kwiimeko ezininzi zokusetyenziswa.

§ i- punctum neutrum

• 🧬 Ubume bedatha, ulwimi lweSolidity, ii-SDKs

Ukuba umtsha kuphuhliso lwe-blockchain, usenokuba uvile ukuba inzima kwaye kunzima ukuyiqala. Nangona kunjalo, oku akuyonyani. Uphuhliso lweBlockchain lusebenzisa iikhonsepthi eziqhelekileyo, i-semantics, kunye ne-syntax, okwenza kube lula ukufunda kunokuba kunokubonakala.

§ Idemo: iRepository Version yesicelo

https://github.com/0xweb-org/examples-backend


Kweli nqaku, masenze isivumelwano somphathi wenguqulelo yesicelo. Khawucinge ukuba unesicelo sedesktop esifuna umva ukuze ukhangele iinguqulelo ezintsha kwaye ufumane ikhonkco lokukhuphela nanini na inguqulelo entsha ipapashwa. Apha ngezantsi sisivumelwano sokugqibela, esibonisa uninzi lwamagama abalulekileyo:


 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]; } }


Wonke umthuthukisi unokufunda kwaye aqonde le khowudi ngomzamo omncinci. Ukuba uqhelene ne-TypeScript, uninzi lweengqikelelo apha ziya kuba sele zinentsingiselo. Ukuyenza icace ngakumbi, ndidale umzekelo olinganayo we-TypeScript: AppVersionManager.ts 🔗 .


Ngamagama alula, ikhontrakthi kuSolidity inokucingelwa njengomzekelo weklasi oncomekayo . Iingqikelelo zeepropathi, iindlela, iintlobo, kunye nelifa sele zaziwa kakhulu kwiprogram ejolise kwinto. Umba ongundoqo oza kuchazwa apha nguMnini onlyOwner umlungisi (ofana nomhombiso kwi-TypeScript).


Yonke iakhawunti ye-blockchain isisitshixo sabucala kunye nesesidlangalaleni. I-ID ye-akhawunti, eyaziwa ngokuba yidilesi , ithathwe kwisitshixo sikawonke-wonke. Xa intengiselwano yenziwe, idilesi yomthumeli igqithiswa msg.sender . Ukusebenzisa oku, sinokugcina idilesi yakho kumakhi (ngexesha lokuthunyelwa kwekhontrakthi). Kamva, isilungisi onlyOwner siqinisekisa ukuba nguwe kuphela, njengomnini wekhontrakthi, onokwenza updateInfo kunye updatePackage imisebenzi. Ukuba omnye umntu uzama ezi ntshukumo, intengiselwano iya kubuyiselwa. Isilungisi onlyOwner sinikezelwe ngekhontrakthi Ownable , eyinxalenye yethala leencwadi le -OpenZeppelin elisetyenziswa ngokubanzi. Eli thala leencwadi libandakanya ezinye iikhontrakthi ezininzi eziluncedo zokuphucula uphuhliso lwe-blockchain.


Esinye isihloko esibalulekileyo sokuxoxa ngumbono weProxies , owahlula ukugcinwa kunye nokuphunyezwa kwiikhontrakthi ezimbini ezahlukeneyo. Ukuphunyezwa kwekhontrakthi kwi-Solidity ayinakuguqulwa, oku kuthetha ukuba awukwazi ukongeza imisebenzi emitsha okanye iipropati emva kokuthunyelwa. Ukuze usebenze malunga noku, unokusebenzisa ikhontrakthi "yeProxy". I-Proxy iphatha ukugcinwa kwaye iqulethe umsebenzi omnye fallback , othumela umnxeba kwikhontrakthi yokuphunyezwa ngelixa ugcina umxholo wokugcina we-Proxy.


Le ngcamango inokuvakala inzima, kodwa iyafana nendlela this kusebenza ngayo kwiJavaScript. Nalu ufaniso olukhawulezayo ukunceda ukucacisa:


 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();


Ikhontrakthi yommeli ibambe ireferensi kwikhontrakthi yomiliselo. Ukuba ufuna ukongeza imisebenzi emitsha, uthumela nje ikhontrakthi yomiliselo entsha kwaye uhlaziye ummeli ukuze abhekisele kule khontrakthi intsha, umsebenzi wokudlulisa umnxeba kumzekelo ohlaziyiweyo. Yinkqubo ethe tye, kodwa kukho i-edge case ekufuneka iqwalaselwe: abakhi.


Xa uhambisa isivumelwano sokuphunyezwa, umakhi wayo usebenza ngaphakathi kokugcinwa kwekhontrakthi yokuphunyezwa ngokwayo. Oku kuthetha ukuba iisethi ezifana title = "Hello World" aziyi kuguqula ugcino lommeli. Ukulungisa oku, sisebenzisa ingqikelelo yomsebenzi wokuqala :

  1. Sebenzisa ikhontrakthi yomiliselo enomsebenzi initialize .
  2. Sebenzisa isivumelwano sommeli, udlulisa idilesi yesivumelwano sokuphunyezwa kumakhi wayo. Olu cwangciso luvumela indlela initialize ukuba ibizwe kumxholo wekhontrakthi yommeli.


Ngenxa yoko, ukuhlaziya ipropati title , umzekelo, kuya kuyihlaziya ngokuchanekileyo kwindawo yokugcina ummeleli.


Nalu usetyenziso oluphuculweyo lwenguqulelo yethu ye-AppVersionManager: AppVersionManagerUpgradeable.sol .


Ikhontrakthi yommeli ngokwayo yeyomhlaba wonke kwaye izimele ekuphunyezweni. Imigangatho emininzi eyaziwayo yeeproxies iyafumaneka kwithala leencwadi le-OpenZeppelin.


Ngolwazi lwezi ngcamango kunye nemizekelo engentla, ukulungele ukuphuhlisa izivumelwano ze-smart kumatyala akho oshishino.

§ Ukusasazwa

  1. Khetha i-blockchain

Okokuqala, kufuneka sikhethe i-blockchain apho sifuna ukuhambisa ikhontrakthi yethu. Kulo mzekelo, ndikhethe iPolygon. Inika iindleko eziphantsi zokuthengiselana, sele ikhona ixesha elide, kwaye iqhube kakuhle. Iziseko zayo ezizinzileyo nezisebenzayo, ezidityaniswe nexabiso elipheleleyo elivaliweyo (i-TVL) ye-0.9 yeebhiliyoni zeedola, lenza ukuba libe lukhetho oluthembekileyo. Ukuhambisa iikhontrakthi zakho kwi-blockchains yoluntu kuthetha ukuhlala kunye namaziko emali. I-metric ye-TVL ibonisa ukuthembela kula maziko ekuthembekeni kwe-blockchain.


Ngaphezu koko, ukuba iimeko ziyatshintsha, unokuhlala uphinda usebenzise isivumelwano kwenye i-blockchain kwixesha elizayo.


  1. Hambisa


Iprojekthi yedemo ikwasebenza njengendawo yovavanyo lweCI, ke yonke imiyalelo inokufumaneka apha: https://github.com/0xweb-org/examples-backend/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


Ngemiyalelo nje embalwa, uye wasebenzisa ikhontrakthi kwaye uhlaziye idatha. Yiyo loo nto ye-backend-ngoku iphezulu kwaye isebenza "ngonaphakade" ngaphandle kokufuna ezinye izenzo ezivela kwicala lakho. Iindleko zolu kuthunyelwa, ngexabiso le-GAS le-70 gwei kunye nexabiso le-POL ye-$ 0.51, iya kuba:



IGAS

IPOL

$

Hambisa

850352

0.059

0.03

Gcina Isihloko

47517

0.0033

0.001

Gcina iPackage Data

169549

0.0118

0.006

Iyonke



0.037


Uchitha nje iisenti ezi-4 ukuseta unikezelo , olukhuselekileyo , kunye nenkonzo ethatha ixesha elide ngaphandle kolungiso olufunekayo.

§ Umbuzo

Ukubuza idatha yakho yekhontrakthi, uya kufuna ababoneleli beendawo ze-RPC. Uninzi lwababoneleli basimahla bafumaneka kwi -https ://chainlist.org. Unokukhetha ababoneleli abaninzi, kwaye ilayibrari yeWeb3 elungileyo inokusebenzisa isicwangciso esijikelezayo ngexesha lokusebenza ukukhetha eyona isebenzayo kubasebenzisi bakho bokugqibela. Nge-0xweb, i-TypeScript eyenziweyo okanye iiklasi zeJavaScript azikhethi kuphela ezona siphelo zilungileyo kodwa zikwakhupha kulo lonke unxibelelwano lwe-blockchain. Abaxhasi baqulethe iindlela eziphezulu zokulanda idatha, okwenza inkqubo ingenamthungo kwaye isebenze kakuhle.

 # 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());


Kwezinye iilwimi zokucwangcisa, kukho amathala eencwadi amaninzi akhoyo ukwenza lula ukubuza imibuzo kwi-blockchain. Emva kokusasazwa, uya kuba nedilesi yesivumelwano kunye ne-ABI (i-interface).


Kungenjalo, unokuqalisa umncedisi we-middleware ukubuza idatha yekhontrakthi usebenzisa i-0xweb.

 npx 0xweb server start --port 3000 curl http://localhost:3000/api/c/read/AppVersionManager/package?chain=polygon


Enye inzuzo kukuba awudingi ukubandakanya nawaphi na amathala kwisicelo sakho-izicelo ze-HTTP ekrwada. Nangona kunjalo, le ndlela ixhomekeke kwiseva eyongezelelweyo oya kuyidinga ukuyilawula. Kudla ngokuba ngcono ukubuza ibhlokhi ngokuthe ngqo usebenzisa iiklasi ezenziwe ngo-0xweb okanye amanye amathala eencwadi ebhloko akhoyo.

§ Isishwankathelo 🏁

Eli nqaku libonise indlela iibhloko ezinokuthi zibe lula kwaye zibe namandla, zibonelela ngeenzuzo ezizodwa xa kuthelekiswa nezisombululo zemveli zokubamba.


Kwinqaku elilandelayo, ndiceba ukuphonononga uthungelwano lokugcinwa kwe-BLOB olunabileyo olunje ngeGreenfield kunye neArweave, ndiqaqambisa iimpawu zabo kunye neenzuzo.


Ukuba unazo naziphi na iingcebiso okanye izimvo ngeempawu ezongezelelweyo onokuzibandakanya kwithala leencwadi lika-0xweb, zive ukhululekile ukwabelana ngazo kwizimvo okanye ufikelele ngqo [email protected] .