paint-brush
Kugadzira Blockchain seBackend Chaizvoizvo Zvakaoma Izvozvi?by@0xtnbts
Nhoroondo itsva

Kugadzira Blockchain seBackend Chaizvoizvo Zvakaoma Izvozvi?

by Alex Kit11m2025/01/17
Read on Terminal Reader

Kurebesa; Kuverenga

Ichi chinyorwa hachisi che cryptocurrency kana decentralized mari. Panzvimbo iyoyo, isu tichaongorora yeruzhinji EVM blockchains uye mashandisiro avanogona kuita mupurojekiti yako inotevera. Ini ndichaongorora zvakanakira, zvakaipa, uye mienzaniso inoshanda, ndichishandisa raibhurari ye0xweb.
featured image - Kugadzira Blockchain seBackend Chaizvoizvo Zvakaoma Izvozvi?
Alex Kit HackerNoon profile picture

Ichi chinyorwa hachizi che cryptocurrency kana decentralized mari. Panzvimbo iyoyo, isu tichaongorora veruzhinji EVM blockchains uye mashandisiro avanogona mupurojekiti yako inotevera, zvichienderana nezvaunoda uye zvinangwa zvako. Ini ndichanyura mune zvakanakira, zvakaipa, uye mienzaniso inoshanda, ndichishandisa raibhurari ye0xweb yandanga ndichishanda pairi.

§ pro et contra

• 🚀 Zero kuseta nguva

Zvatova kusimuka. Ingo tsanangura yako data modhi sekondirakiti uye woitumira.

• ✨ Zero kugadzirisa

Kana data rako raiswa, rinoramba richiwanikwa chero bedzi blockchain ichishanda. Ini ndinogona kufunga kuti ichave yakareba kureba kupfuura imwe yako yekutambira kunyorera.

• 💯 100% Verenga uptime; pedyo ne100% Nyora nguva

Kupatsanurwa kwekuverenga nekunyora maitiro mu blockchain kunovimbisa 100% uptime yekuverenga mashandiro, kunyanya kana kusimudzira akawanda RPC vanopa redundancy.

• 🛡️ Chengetedza

MaBlockchains anogara anopa yakakwira mwero wekuchengetedza pane akajairwa kugadzirisa mhinduro. Kushandiswa kwedata kunogoneka chete kana kusadzivirirwa kuripo mune yako data model logic.

• 📖 Vhura Data

Kunze kwekunge yakavharidzirwa, data rako rinoramba rakavhurika, rinowanikwa, uye rinoonekwa nemunhu wese, achisimudzira kubuda pachena.

• 🖧 DNS-Yemahara

Mazita eDomain haafanirwe kune iyi mhando yebackend. Pane kudaro, runyoro rwevanopa node vanopa vanogona kushandiswa, vachibvumira maraibhurari evatengi kusarudza iyo inonyanya kushanda sarudzo yevashandisi vekupedzisira.

• 🤝 Vimba

Kutenda kune izvo zviri pamusoro, blockchain-based backends inovaka mushandisi kuvimba nekuona kuchengetedzwa kwedata uye kuwanikwa kwe24/7, kunyangwe kugadzirisa kweprojekiti nekusimudzira kwakamira.

• 🧩 Kusawirirana nevechitatu bato data modhi

Iwe unogona kubatanidza mamwe ma data data akachengetwa pa blockchain, kana mamwe mapurojekiti anogona kuvaka pane yako data data.

• ⚙️ Kuwedzera

Vashandisi vanogona kukwirisa akawanda echitatu-bato mapurojekiti kuti atarise kana otomatiki zviito, achiwedzera zvakanyanya mikana yemhando yako yedata.

• 📜 Nhoroondo uye nguva-kufamba

Iyo data inogona kuwanikwa kubva kune chero nzvimbo munguva yakapfuura.

• 📡 Zviitiko uye chiitiko-nzizi

Rodha zviitiko zvezvakaitika kare kana kushandisa WebSockets kuti uteerere zviitiko zvenguva chaiyo zvinouya, zvichigonesa mhinduro dzemaapplication.

• 👤 Yakavakirwa-mukati mushandisi kuzivikanwa

Iyo "wallet" pfungwa inogonesa vashandisi kuti vazvisimbise ivo pachavo nekusaina mameseji, vachipa isina musono uye decentralized mushandisi kuzivikanwa.

• 📝 Ipa vashandisi kugadzirisa kana kuwedzera data

Vashandisi vanogona kugadzirisa kana kuwedzera data mukuchengetedza kwako zvichienderana nemvumo yaunotsanangura. Zvakakosha, mari yezvigadziriso izvi inotakurwa nevashandisi pachavo. Nekusarudza blockchain ine mutengo wakaderera, mari idzi dzinogona kuramba dzisina basa, kazhinji dzinosvika masendi mashoma pakutengeserana.

• 🌐 Hombe uye inoramba ichichinja ecosystem

  • akawanda solidity modules aunogona kushandisa kusimudzira yako data modhi mashandiro.
  • akawanda akavhurika-sosi uye emahara masevhisi, pamwe neaya anopa zvirongwa zvemahara, aripo. Icho chiitiko chakajairwa mukati me blockchain nharaunda kupa zvirongwa zvemahara izvo zvinowanzokwana kune zvinodiwa zvekugadzira.

§ contra

• 💾 Storage inodhura 😢

Kunyangwe ichitevera yechokwadi pay-as-you-go modhi, iwe unobhadhara chete kune maSLOTs aunochengetera. Imwe neimwe SLOT ine 32 bytes, inodhura 20000 GAS kunyora data nyowani kana 5000 GAS kugadzirisa data. Ngatitorei Polygon semuenzaniso, ine 30-gwei GAS mutengo uye $0.60 POL mutengo.


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


Izvi zvakawandisa, saka iyo "Floppy Disk" emoji inomiririra huwandu hwekuchengetera nenzira yakanakisa, zvinoreva kuti yakanyatsokodzera madiki dataset kana iwe uchibhadhara wega. Nekudaro, mukana wakasarudzika nderekuti vashandisi vanogona kutakura mutengo wekuchengetedza kwavo uye zviito, chinhu chisingawanikwe mune mamwe matekinoroji. Nepo nzira iyi inogona kutadzisa kutorwa kwevazhinji kweapp yako, inogamuchirwa zvakanyanya mukati me blockchain nharaunda.

• 🧮 Computation ishoma 😢

Blockchain data modhi inotsigira mabasa ekudyidzana neiyo data, asi kugona kwavo komputa ine zvipingaidzo. Izvi zvinogumira zvinoenderana neRPC node dzaunoshandisa pakuverenga zviito uye iyo yakasimba GAS miganho yakatemerwa pane kunyora zviito (transaction). Nepo mabasa ekutanga, zvishwe, uye zvakadzika zvekufona stacks zvinowanzogoneka, iyo blockchain haina kukodzera kune inorema computational basa.


Izvo zvakati, zvichipihwa diki data saizi inowanzobatanidzwa, iyo iripo miganho inowanzokwana kune akawanda ekushandisa kesi.

§ punctum neutrum

• 🧬 Data chimiro, Solidity mutauro, SDKs

Kana iwe uri mutsva ku blockchain development, unogona kunge wakanzwa kuti zvakaoma uye zvakaoma kutanga nazvo. Zvisinei, ichi hachisi chokwadi. Kuvandudzwa kweBlockchain kunoshandisa pfungwa dzinozivikanwa, semantics, uye syntax, zvichiita kuti zvive nyore kudzidza pane zvingaite.

§ Demo: Chikumbiro Shanduro Repository

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


Kune chinyorwa ichi, ngatigadzire kondirakiti yemaneja yeshanduro yeapp. Fungidzira iwe une desktop application inoda kuseri kuti utarise shanduro nyowani uye tora iyo yekurodha link pese panoburitswa vhezheni. Pazasi pane kondirakiti yekupedzisira, inoratidza mazhinji epfungwa dzakakosha:


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


Wese anovandudza anogona kuverenga uye kunzwisisa iyi kodhi nekushoma kuedza. Kana iwe uchijairana neTypeScript, mazhinji epfungwa pano anotoita zvine musoro. Kuti zvinyatsojeka, ndagadzira yakafanana TypeScript muenzaniso: AppVersionManager.ts 🔗 .


Nemashoko akapfava, kondirakiti muSolidity inogona kutorwa seyakajeka kirasi muenzaniso . Mafungiro ezvivakwa, nzira, marudzi, uye nhaka atove anozivikanwa muchirongwa chinonangana nechinhu. Pfungwa huru yekutsanangura pano ndiyo onlyOwner modifier (yakafanana neinoshongedza muTypeScript).


Yese blockchain account ndeyechokwadi makiyi akavanzika uye eruzhinji. ID yeakaundi, inozivikanwa sekero , inotorwa kubva kukiyi yeruzhinji. Kana kutengeserana kuchiitwa, kero yemutumiri inotambidzwa se msg.sender . Tichishandisa izvi, tinogona kuchengetedza kero yako muvaki (panguva yekuendesa chibvumirano). Gare gare, iyo onlyOwner Mugadziri wekugadzirisa inovimbisa kuti iwe chete, semuridzi wekondirakiti, unogona kuita iyo updateInfo uye updatePackage mabasa. Kana mumwe munhu akaedza kuita izvi, kutengeserana kunodzoserwa. Iyo onlyOwner modifier inopihwa Ownable contract, inova chikamu cheraibhurari inoshandiswa zvakanyanya- OpenZeppelin . Iyi raibhurari inosanganisira zvimwe zvakawanda zvinobatsira zvibvumirano zvekugadzirisa blockchain kusimudzira.


Imwe nyaya yakakosha yekukurukura ipfungwa yeProxies , inopatsanura kuchengetedza uye kuita kuita zvibvumirano zviviri zvakasiyana. Kuitwa kwechibvumirano muSolidity hakuchinji, zvichireva kuti haugone kuwedzera mabasa matsva kana zvivakwa mushure mekutumirwa. Kuti ushande pane izvi, unogona kutumira "Proxy" chibvumirano. Iyo Proxy inobata chengetedzo uye ine imwechete fallback basa, iyo inotumira inodaidza kuchibvumirano chekuita ichichengetedza mamiriro ekuchengetedza eProxy.


Iyi pfungwa inogona kuita seyakaoma, asi yakafanana nemashandiro anoita this muJavaScript. Heino fananidzo yekukurumidza kubatsira kujekesa:


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


Kondirakiti yeproxy inobata chirevo chechibvumirano chekushandisa. Kana iwe uchida kuwedzera mabasa matsva, iwe unongoendesa kondirakiti nyowani yekumisikidza uye gadziridza proxy kuti itaure iyi chibvumirano chitsva, kuendesa basa rekufona kune yakagadziridzwa muenzaniso. Iyo yakatwasuka maitiro, asi pane edge kesi yekufunga: vagadziri.


Pakuisa chibvumirano chekushandisa, muvaki wayo anoshanda mukati mekuchengetwa kwekontrakiti yekushandisa pachayo. Izvi zvinoreva kuti seta senge title = "Hello World" haizogadzirise kuchengetedza kwemumiriri. Kugadzirisa izvi, tinoshandisa iyo yekutanga basa pfungwa:

  1. Shandisa chibvumirano chekushandisa initialize basa.
  2. Tumira chibvumirano chemumiriri, uchipfuudza kero yekondirakiti yekushandisa mugadziri wayo. Iyi setup inobvumira nzira initialize kudanwa mumamiriro echibvumirano cheproxy.


Nekuda kweizvozvo, kuvandudza iyo title , semuenzaniso, ichaigadziridza nemazvo mukuchengetedza proxy.


Heinoi shanduro yakakwidziridzwa yekushandisa yedu AppVersionManager: AppVersionManagerUpgradeable.sol .


Iyo proxy kontrakiti pachayo ndeyepasirese uye yakazvimirira pakuitwa. Akawanda anozivikanwa mazinga emaproxies anowanikwa muraibhurari yeOpenZeppelin.


Neruzivo rweaya mazano uye nemienzaniso iri pamusoro, iwe wakagadzirira kugadzira akangwara zvibvumirano zvebhizinesi rako kesi.

§ Kuendeswa

  1. Sarudza blockchain

Kutanga, isu tinofanirwa kusarudza iyo blockchain kwatinoda kuendesa kontrakiti yedu. Pamuenzaniso uyu, ndakasarudza Polygon. Inopa mutengo wakaderera wekutengesa, yave iripo kwenguva yakareba, uye yakagara ichiita zvakanaka. Zvigadzirwa zvayo zvakagadzikana uye zvinoshanda, zvakasanganiswa neTotal Value Locked (TVL) ye $ 0.9 bhiriyoni, inoita kuti ive sarudzo yakavimbika. Kuendesa zvibvumirano zvako kuruzhinji blockchains zvinoreva kugarisana nemasangano emari. Iyo TVL metric inoratidza kuvimba nemasangano aya anoisa mukuvimbika kwe blockchain.


Uyezve, kana mamiriro akachinja, unogona kugara uchitumirazve kontrakiti kune imwe blockchain mune ramangwana.


  1. Deploy


Iyo demo purojekiti inoshandawo seCI bvunzo repository, saka mirairo yese inogona kuwanikwa pano: 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


Nemirairo mishoma, iwe waendesa kontrakiti uye nekuvandudza data. Ndizvo zvazvinoita zvekumashure-yave kusimuka uye ichimhanya "nokusingaperi" isingade chimwe chiito kubva kudivi rako. Mutengo wekutumirwa uku, pamutengo weGAS wemakumi manomwe gwei uye mutengo wePOL wemadhora 0.51, ungave:



GAS

POL

$

Deploy

850352

0.059

0.03

Save Title

47517

0.0033

0.001

Sevha Package Data

169549

0.0118

0.006

Total



0.037


Iwe unongopedza masendi mana kumisikidza yakasarudzika , yakachengeteka , uye yakareba-inoshanda sevhisi pasina kugadzirisa kunodiwa.

§ Mubvunzo

Kuti ubvunze data rako rechibvumirano, iwe uchada RPC node vanopa. Mazana evanopa vakasununguka anowanikwa pa https://chainlist.org . Iwe unogona kusarudza vazhinji vanopa, uye yakanaka Web3 raibhurari inogona kushandisa yakatenderedza-robin zano panguva yekumhanya kusarudza iyo inonyanya kushanda kune yako yekupedzisira vashandisi. Iine 0xweb, iyo yakagadzirwa TypeScript kana JavaScript makirasi haango sarudza akanakisa ekupedzisira asiwo abstract kure kwese blockchain kutaurirana. Vatengi vane nzira dzepamusoro-soro dzekutora data, zvichiita kuti hurongwa huve husina mutsetse uye hunobudirira.

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


Kune mimwe mitauro yekuronga, kune akawanda maraibhurari anowanikwa kurerutsa kubvunza iyo blockchain. Mushure mekutumirwa, iwe unenge uine kero yekondirakiti uye ABI (interface).


Neimwe nzira, unogona kuvhura sevha yepakati kubvunza data rechibvumirano uchishandisa 0xweb.

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


Imwe mukana ndeyekuti haufanire kusanganisa chero maraibhurari mune yako application - mbishi zvikumbiro zveHTTP. Nekudaro, iyi nzira inotsamira pane imwe sevha yauchazoda kubata. Kazhinji zviri nani kubvunza blockchain zvakananga uchishandisa 0xweb-yakagadzirwa makirasi kana mamwe blockchain maraibhurari aripo.

§ Pfupiso 🏁

Ichi chinyorwa chakaratidza kuti blockchains inogona sei kuve yakapusa uye ine simba, ichipa yakasarudzika mabhenefiti kana ichienzaniswa neyakajairwa kugadzirisa mhinduro.


Muchinyorwa chinotevera, ini ndinoronga kuongorora yakatemerwa BLOB chengetedzo network seGreenfield neAweave, ndichisimbisa maitiro avo uye mabhenefiti.


Kana iwe uine chero mazano kana mazano ekuwedzera maficha ekusanganisira muraibhurari ye0xweb, sununguka kuagovera mumashoko kana kuti taura zvakananga pa [email protected] .