paint-brush
Sida loo Abuuro Goob Suuq ah oo Baahsan oo loogu talagalay Alaabooyinka Beeraha ee RSK Testnetby@induction
605 akhrin
605 akhrin

Sida loo Abuuro Goob Suuq ah oo Baahsan oo loogu talagalay Alaabooyinka Beeraha ee RSK Testnet

by Vision NP13m2024/09/30
Read on Terminal Reader

Aad u dheer; In la akhriyo

Tiknoolajiyadu waa inay ku jirtaa adeegga aadanaha. Tiknoolajiyada loo yaqaan 'Blockchain technology', oo horey u rogtay qaybo badan, waxay sidoo kale bedeli kartaa beerta. Si aan u keenno tignoolajiyadan baahsan ee habka korsashada caadiga ah, waa in aan fududeeyno si aan u gaarno dadweynaha si aan u galno isticmaalayaasha ballaaran, ugu dambeyntii kordhinta kiisaska isticmaalka.
featured image - Sida loo Abuuro Goob Suuq ah oo Baahsan oo loogu talagalay Alaabooyinka Beeraha ee RSK Testnet
Vision NP HackerNoon profile picture
0-item
1-item
2-item

Tiknoolajiyadu waa inay ku jirtaa adeegga aadanaha. Tiknoolajiyada loo yaqaan 'Blockchain technology', oo horey u beddeshay qaybo badan, waxay sidoo kale bedeli kartaa beerta. Si aan u keenno tignoolajiyadan baahsan ee habka korsashada caadiga ah, waa in aan fududeeyno si aan u gaarno dadweynaha si aan u galno isticmaalayaasha ballaaran, ugu dambeyntii kordhinta kiisaska isticmaalka.


Tababarkan, waxaan ku dhisi doonaa arji baahsan (dApp) kaas oo u ogolaanaya isticmaalayaasha inay iibsadaan oo ay ku iibiyaan wax soo saarka beeraha ee Rootstock (RSK) ee shabakada blockchain. Ujeedada ugu weyn waa in la dhiso dApp ka shaqeeya shabakada blockchain. Nooc kasta oo isticmaaleyaal ah ayaa si fudud ugu dari kara alaabooyin si ay u kasbadaan iyagoo iibinaya wax soo saarkooda beeraha iyada oo aan faragelin bini'aadmi ah oo xad dhaaf ah la helin.


Markii hore, abka waxa lagu tijaabiyay Rootstock's testnet, oo waxa ay ku dhawdahay xaalad wax soo saar u diyaarsan (waxa loo baahday wax ka bedel yar si loogu wareego shabakada guud ee Rootstock). Mashruucu mar hore ayaa lagu shubay GitHub si aad kaliya u xidhi karto kaydka si aad naftaada u tijaabiso.


Tan, waxaan doorbidayaa Readme.md on GitHub . Laakin, casharradan, waxaan isku dayeynaa inaan si qoto dheer u hagno si nooc kasta oo isticmaale ah uu u dhisi karo dApp-kiisa iyadoo ay fududahay in la fahmo casharrada si tallaabo ah. Waxaa laga yaabaa inaan kuu soo jeedino inaad ka soo dejiso koodka Frontend kaydka GitHub, oo aad ku darto hagaha habboon. Waxaan dabooli doonaa wax walba laga bilaabo dejinta mashruuca ilaa geynta qandaraasyada smart iyo abuurista Frontend is dhexgal leh oo leh astaamo-waqtiga dhabta ah.


Kahor intaanan bilaabin, waxaan hiigsaneynaa inaan dhisno dApp lagu magacaabo AgriMarket kaas oo la filayo inuu yeesho sifooyinka soo socda:

  • Waxay u ogolaataa isticmaalayaasha inay ku galaan sifada Web3 iyagoo adeegsanaya boorsooyinka la taageeray (MetaMask kiiskeena).
  • Waxay u ogolaataa isticmaalayaasha inay ku daraan wax soo saarkooda beeraha qiimahooda iyagoo ku xiraya boorsadooda dApp-ka.
  • Appku waxa uu xaqiijiyaa wicitaanada qandaraasyada caqliga leh isagoo la falgalaya MetaMask.
  • Isticmaalayaashu waxay ku dari karaan alaabada ku jirta gaariga iyo dApp waxay awoodaan inay bilaabaan macaamil ganacsi xitaa haddii ay jiraan alaabooyin badan oo ku jira gaariga.
  • Isticmaalayaashu waxay heli karaan ogeysiisyada waqtiga-dhabta ah, rasiidhada wax kala iibsiga, iyo sifooyinka ka saarista alaabta labada baabuur iyo sidoo kale bogga liiska alaabta.

📥 Shuruudaha - Kahor intaanan bilaabin, hubi inaad ku rakibtay mashiinkaaga waxyaabaha soo socda:

  • Node.js (v14 ama ka sareeya)
  • npm ama dun
  • Truffle ama Hardhat ee horumarinta qandaraasyada smart
  • Kordhinta MetaMask waxaa loo habeeyey testnetka RSK
  • Git ee xakamaynta nooca
  • IDE sida VScode

📥 Dejinta Mashruuca

👉Samee Hagaha Mashruuca


Fadlan hubi inaad door bidayso buug-tusaha mashruuca ugu weyn inta lagu jiro dhammaan habkayaga horumarinta iyo tijaabinta.


Jaantuska 1. Hagaha Mashruuca


👉Bilow Hagaha Mashruuca

U samee hage cusub mashruucaaga adoo ku socodsiinaya amarada soo socda terminalka:

 mkdir rsk-agri-marketplace cd rsk-agri-marketplace


👉Bilow mashruuc cusub oo npm:

 npm init -y


👉Bilow Mashruuca Truffle


Waxaan u isticmaaleynaa Truffle si aan u ururinno oo u horumarino qandaraaska caqliga leh si aad ugu bilowdid hagaha xididka:

 truffle init


Tani waxay abuurtaa qaab dhismeedka aasaasiga ah: • contracts/ - Waxa ku jira heshiisyo adagmigrations/ - Qoraallada hawlgelintatest/ - Tijaabada qandaraasyadaadatruffle-config.js - faylka qaabeynta Truffle


📥Habee Isbeddellada Deegaanka

Macluumaadka xasaasiga ah sida furayaasha gaarka ah, Pimata API Key, iwm waa in lagu kaydiyaa faylka .env.


👉Ku rakib dotenv

 npm install dotenv


👉Samee faylka .env


Hagaha xididka, ku samee faylka .env oo leh qaabkan soo socda:

 REACT_APP_PINATA_API_KEY=Your API Key REACT_APP_PINATA_SECRET_API_KEY=Secret API Key MNEMONIC=12 words mnemonic key RSK_TESTNET_URL=https://public-node.testnet.rsk.co REACT_APP_CONTRACT_ADDRESS=Contract Address


Fadlan samee faylka .env la'aanteed boosas dheeri ah ama dabeecad xumo haddii kale waxaad la kulmi doontaa dhibaatooyin hadhow. Fadlan, xasuuso Tallaabadan sababtoo ah waxaad cusbooneysiineysaa qandaraaska caqliga leh hadhow. Ka hel Pinata API halkan .

📥Ku xidhidhiyaha RSK Testnet

👉Cusbooneysii truffle-config.js


Waxaad ku arki kartaa truffle-config.js-ka la sameeyay ee hagaha mashruucaaga. Kaliya cusboonaysii koodka si aan ula falgeli karno testnetka RSK iyada oo loo marayo.

 require('dotenv').config(); const HDWalletProvider = require('@truffle/hdwallet-provider'); module.exports = { networks: { development: { host: "127.0.0.1", port: 8545, network_id: "*", }, rskTestnet: { provider: () => new HDWalletProvider({ mnemonic: { phrase: process.env.MNEMONIC, }, providerOrUrl: `https://public-node.testnet.rsk.co`, chainId: 31, // RSK Testnet ID pollingInterval: 15000, }), network_id: 31, gas: 2500000, gasPrice: 60000000, confirmations: 2, timeoutBlocks: 60000, skipDryRun: true, }, }, compilers: { solc: { version: "0.8.20", }, }, db: { enabled: false, }, };


👉Rakib Bixiyaha HDWallet

 npm install @truffle/hdwallet-provider

📥 Horumarinta Qandaraaska Wacan

Waxaan abuuri doonaa qandaraas suuqa.


👉Rakib qandaraasyada OpenZeppelin

Waxaan u isticmaaleynaa qandaraasyada OpenZeppelin si aan u wanaajino amniga iyo habsami u socodka qandaraaskeena smart, markaa ku rakib adiga oo ku socodsiinaya amarka soo socda ee terminalka:

 npm install @openzeppelin/contracts


👉Ku samee Marketplace.sol contracts/ tusaha:

 // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import "@openzeppelin/contracts/utils/Pausable.sol"; contract Marketplace is ReentrancyGuard, Pausable { uint public productCount = 0; struct Product { uint id; address payable seller; string name; string description; string imageHash; // IPFS hash uint price; // Price in tRBTC bool active; } mapping(uint => Product) public products; event ProductCreated( uint id, address seller, string name, string description, string imageHash, uint price, bool active ); event ProductPurchased( uint id, address seller, address buyer, uint price ); event ProductRemoved(uint id, address seller); function createProduct( string memory _name, string memory _description, string memory _imageHash, uint _price ) public whenNotPaused { require(bytes(_name).length > 0, "Name is required"); require(_price > 0, "Price must be positive"); // Price is expected in tRBTC productCount++; products[productCount] = Product( productCount, payable(msg.sender), _name, _description, _imageHash, _price, true ); emit ProductCreated( productCount, msg.sender, _name, _description, _imageHash, _price, true ); } function purchaseProducts(uint[] memory _ids) public payable nonReentrant whenNotPaused { uint totalCost = 0; for (uint i = 0; i < _ids.length; i++) { Product storage _product = products[_ids[i]]; require(_product.id > 0 && _product.id <= productCount, "Invalid product ID"); require(_product.active, "Product is not active"); require(_product.seller != msg.sender, "Seller cannot buy their own product"); totalCost += _product.price; } require(msg.value >= totalCost, "Insufficient funds"); for (uint i = 0; i < _ids.length; i++) { Product storage _product = products[_ids[i]]; (bool success, ) = _product.seller.call{value: _product.price}(""); require(success, "Transfer failed to the seller"); // Emit purchase event (product can be bought again) emit ProductPurchased( _product.id, _product.seller, msg.sender, _product.price ); } } function removeProduct(uint _id) public { Product storage _product = products[_id]; require(_product.id > 0 && _product.id <= productCount, "Invalid product ID"); require(_product.seller == msg.sender, "Only the seller can remove the product"); _product.active = false; // Mark the product as inactive emit ProductRemoved(_id, msg.sender); } function getProduct(uint _id) public view returns (Product memory) { require(_id > 0 && _id <= productCount, "Invalid product ID"); Product memory product = products[_id]; require(product.active, "Product is not available"); return product; } function pause() public { _pause(); } function unpause() public { _unpause(); } }


👉Ku qor qoraalka socdaalka migrations/2_deploy_contracts.js

 const Marketplace = artifacts.require("Marketplace"); module.exports = function (deployer) { deployer.deploy(Marketplace); };


👉Uruuri oo Geli Qandaraasyada

Ku socodsii koodka soo socda si aad u ururiso heshiiska iyada oo loo marayo terminalka:

 truffle compile


Haddii wax waliba si sax ah u dhacaan, waxaad ku arki kartaa wax sidan oo kale ah terminalka:

Jaantus 2. Isku-dubarid qandaraas adiga oo isticmaalaya Truffle


Ku socodsii amarka soo socda ee terminalka si aad u geyso Marketplace.sol testnetka Rootstock.

 truffle migrate --network rskTestnet

Waxaad u baahan tahay xoogaa tRBTC ah boorsada jeebka ka hor intaadan darin heshiiskaaga. Ka hel qasabada RSK halkan .

Habka guusha ka dib, waxaad ku arki doontaa fariinta terminalka soo socda:

Jaantuska 3.Heshiiska la geeyay RSK testnet

Waxaad ka heli doontaa faylka Marketplace.json gudaha \build\contracts\Marketplace.json xusuusnow, waxaad nuqul ka samayn doontaa faylkan hage kale.


Horumarinta Hore ee Suuqa Suuqa dApp


Hadda oo aanu geynay qandaraasyada casriga ah, waxaan u dhisi doonaa suuq soo jiidasho leh oo u oggolaanaya isticmaaleyaasha inay la falgalaan. Qaybta hore waxay yeelan doontaa sifooyin sida liisaska alaabta, ku darista alaabada, gadashada, ku darista/saarida alaabta gaadhiga, la socodka macaamilka, iyo bixinta jawaab celinta wakhtiga dhabta ah sida ogeysiisyada iyo bar horumarka.

📥 Horumarka Hore

👉Bilow Codsiga Falcelinta

Waxaan u isticmaali doonaa React dhanka hore.


Ku billow abka cusub ee React tusaha mashruuca.

 npx create-react-app client


U gudub hagaha macmiilka.

 cd client


Ku rakib Web3 iyo Bootstrap UI

 npm install web3 bootstrap


👉Qaabka Mashruuca

Waxaad u baahan doontaa qaab dhismeedka geesta hore sida ku cad sawirka 1.


👉Web3 ku samee src/utils/Marketplace.json

Si loola macaamilo qandaraaska caqliga leh, waxaanu soo dejin doonaa ABI (Codsiga Binary Interface).

  • Ka guuri Marketplace.json ABI hagahaaga build/contracts ee Truffle galka client/src/utils/ folder sida ku xusan Tallaabada .


  • Dejinta Web3 waxay ku jirtaa faylka App.js Ka soo deji GitHub oo dhig tusaha ku habboon sida ku cad sawirka 1.


👉 Ogeysiinta waqtiga-dhabta ah iyo Baararka Horumarka

Ogeysiinta-waqtiga-dhabta ah, waxaanu isku dari doonaa react-toastify u eg maktabad. Waxa kale oo aad isticmaali kartaa react-bootstrap ee baararka horumarka.


Ku rakib React Toastify tusaha client

 npm install react-toastify


👉Ku rakib Axios codsiyada HTTP (ee Pinata's API):

 npm install axios


Hagaag, hadda fadlan kala soo bax dhammaan qaybaha Frontend galka macmiilka (oo ay ku jiraan gal+faylalka) ee kaydka GitHub . Oo geli tusaha ku habboon.

📥Taabashooyinka ugu dambeeya iyo la falgalka App-kaaga

👉Hadda, waxaad la falgali kartaa dApp-kaaga. Waxaad ku socodsiin kartaa app-ka falcelinta adiga oo isticmaalaya amarka soo socda ee terminalka:

 npm start


Waxay si toos ah u furi doontaa browserka caadiga ah. Fadlan hubi inaad haysato kordhinta biraawsarka MetMask oo si habboon loo habeeyey testnet RSK (Waxaad raaci kartaa hagaha mashruuca si aad u doorato shabakadda saxda ah halkan ).


Hadda, ka falcelinta abka waxay ku baaqaysaa kordhinta jeebka MetaMask, fadlan xaqiiji wicitaanka. Kadib waxay soo bandhigi doontaa boorsada ku xiran isdhexgalka ugu muhiimsan sida ku cad shaxanka soo socda.

Jaantuska 4. UI-ga ugu weyn ee dhinaca hore



Qaybta hore waxay ku siinaysaa astaamo badan. Waxaad ku dari kartaa/ka saari kartaa alaabta. Mar kasta, waxaa lagu weydiin doonaa inaad xaqiijiso wacitaanka ku jira kordhinta jeebka MetaMask. Hubi gif-ka soo socda:


Gif 1. Habka lagu daro alaabta xagga hore ee dAppka


Hagaag, hadda waxaad tijaabin kartaa in dAppku si sax ah u maareeyo macaamilada lagu daray gaariga iyo in kale. Waxaad arki kartaa taariikhda macaamil ganacsi oo faahfaahsan oo hoos timaada qaybta "Taariikhda Ganacsiga" oo leh dhammaan faahfaahinta farsamada. Marka iibka la dhammeeyo, sanduuqa waxaa loo diraa milkiilaha ku daray alaabta dApp-ka.


Aan si wadajir ah u tijaabinno App-ka:

Gif 2. dApp si buuxda u shaqaynaysa si loo farsameeyo wax kala iibsiga gaadhiga


Hambalyo! Waxaan si guul leh u horumarinay oo ku tijaabinay dApp-ka gudaha testnetka RSK. Waxaad u bedeli kartaa shabakada RSK adigoo ku daraya sifooyinka aad rabto. Kaliya hagaaji koodka meel kasta oo testnet lagu sheegay oo sidoo kale ka hubi dukumentiga mashruuca halkan haddii aad u yaacdo si aad u dhisto abka diyaarsan ee wax soo saarka.

📥 Caqabadaha iyo Mustaqbalka:

Waxay noqon doontaa habka cusub ee lagu bilaabayo suuqa beeraha kaas oo ay ku jiraan dhowr habab sida keenista alaabta, soo qaadis, iwm Caqabadda kale ayaa ah in ay wali ku jirto wajigii tijaabada, mana garanayno sida ay macaamiishu u dhaqmaan tignoolajiyadan horumaraysa.


Markaa, waxbarashada iyo tabobarku waxay lama huraan u yihiin beeralayda iyo macaamiisha labadaba si ay u qaataan tignoolajiyada cusub. Sidoo kale, wada shaqayn ku filan ayaa ah arrimaha ugu muhiimsan ee lagu horumarinayo suuq-geyn baahsan oo waara ee wax soo saarka beeraha.

Gabagabo:

Waxaan si guul leh uga dhisnay goob suuq-beereed oo baahsan oo ku taal xiniinyaha Rootstock (RSK). Nabadgelyada ayaa loo qaatay mudnaanta koowaad waana sababta dhowr tillaabo loo qaaday si loo ilaaliyo koodhka qandaraasyada casriga ah iyadoo la adeegsanayo qandaraasyada OpenZeppelin. dApp-ka la tijaabiyay waxa uu ka kooban yahay ku dhawaad dhammaan sifooyinka lagama maarmaanka ah ee ay tahay in goob suuqeed fudud oo baahsani lahaato, laakiin waxaad ku wanaajin kartaa sifooyin badan haddii aad qorshaynayso in aad app ka bilowdo shabakada Rootstock's mainnet. Sidoo kale, maskaxda ku hay ammaanka si aad u hubiso in wax walba u shaqeeyaan sidii loogu talagalay oo si habsami leh.


Waxaan isku daynay in aan ka faa'iidaysanno Rootstock sifooyin wax kala beddelasho degdeg ah leh oo leh kharashyo wax kala beddelasho yar si aan u sii wadno dhammaan wax kala iibsiga taas oo xallin doonta arrinta ciriiriga ah ee Bitcoin ee caanka ah. Dabcan, noocyadan suuqyada suuqyada ah waa inay wajahaan arrimo badan, laakiin sida aan si dabiici ah u raadineyno xorriyadda, waxaan rajeyn karnaa inaan helno goob suuq ah oo baahsan mustaqbalka.