Sava lalana Avy amin'ny fahatakarana ny antontam-teknolojia ho an'ny fampandrosoana Web3 DApp, dia tsy maintsy nianatra ny antontam-teknolojia fototra ho an'ny fivoaran'ny web3 dApp ianao, ny andraikitry ny RPC amin'ny fampivoarana dApp, ary ny fomba fampiasana dRPC hamoronana kaonty, mamorona fanalahidin'ny API, teboka farany, analyse endpoints. , ampio vola amin'ny kaontinao dRPC, ary jereo ny fifandanjanao. Ny anjara asan'ny dRPC amin'ny fametrahana fifanarahana marani-tsaina dia ny fanatsorana ny fizotran'ny fananganana node Ethereum, izay manamora ny fifandraisan'ny mpamorona sy ny fametrahana azy amin'ny andalana kaody tokana. Amin'ity lahatsoratra ity, hanoratra, hanangona, hizaha toetra ary hametraka fifanarahana marani-tsaina momba ny fandoavana kafe amin'ny Ethereum Sepolia Testnet ianao amin'ny fampiasana dRPC endpoint sy API key. Ny endri-javatra dia ahitana: Fandoavana ny kafe Famerenana ny vidin'ny Kafe Famerenana ny totalin'ny kafe amidy sy ny totalin'ny vola azo Aleo holotoina ny tananao. zavatra takiana alohan'ny Efa mamatsy vola amin'ny Sepolia Faucet ny kaontinao. Manana Wallet, ohatra, Metamask. Code Editor. Efa nametraka tranomboky na rafitra Js tianao (oh React.js, Next.js sns). Siny rano. Teknolojia sy fitaovana ilaina Solidity. React.js mampiasa Vite.js(Typescript) Hardhat. Web3.js. Dotenv. dRPC API Key sy Endpoint. Ny kaontinao fanalahidy manokana. MetaMask Manoratra ny fifanarahana Smart Payment Coffee Mamorona lahatahiry iray eo ambanin'ny lahatahiry fakanao, ary omeo anarana hoe . contracts Mamorona rakitra eo ambanin'ny lahatahiry , ary omeo anarana hoe . contracts coffee.sol hampiasa solidity ianao hanoratana ny fifanarahana marani-tsaina. Ny rakitra Solidity dia nomena anarana miaraka amin'ny fanitarana satria io no fanitarana rakitra mahazatra ho an'ny kaody loharano Solidity. .sol Ampio ity kaody loharano manaraka ity amin'ny : coffee.sol // SPDX-License-Identifier: MIT pragma solidity >=0.8.0 <0.9.0; contract Coffee { uint256 public constant coffeePrice = 0.0002 ether; uint256 public totalCoffeesSold; uint256 public totalEtherReceived; // Custom error definitions error QuantityMustBeGreaterThanZero(); error InsufficientEtherSent(uint256 required, uint256 sent); error DirectEtherTransferNotAllowed(); // Event to log coffee purchases event CoffeePurchased(address indexed buyer, uint256 quantity, uint256 totalCost); // Function to buy coffee function buyCoffee(uint256 quantity) external payable { if (quantity <= 0) { revert QuantityMustBeGreaterThanZero(); } uint256 totalCost = coffeePrice * quantity; if (msg.value > totalCost) { revert InsufficientEtherSent(totalCost, msg.value); } // Update the total coffees sold and total ether received totalCoffeesSold += quantity; totalEtherReceived += totalCost; console.log("Total ether received updated:", totalEtherReceived); console.log("Total coffee sold updated:", totalCoffeesSold); // Emit the purchase event emit CoffeePurchased(msg.sender, quantity, totalCost); // Refund excess Ether sent if (msg.value > totalCost) { uint256 refundAmount = msg.value - totalCost; payable(msg.sender).transfer(refundAmount); } } // Fallback function to handle Ether sent directly to the contract receive() external payable { revert DirectEtherTransferNotAllowed(); } // Public view functions to get totals function getTotalCoffeesSold() external view returns (uint256) { console.log("getTotalCoffeesSold :", totalCoffeesSold); return totalCoffeesSold; } function getTotalEtherReceived() external view returns (uint256) { console.log("getTotalEtherReceived :", totalEtherReceived); return totalEtherReceived; } } Pragma : Ity famantarana ny fahazoan-dàlana ity dia manondro fa ny kaody dia nahazo alalana amin'ny alalan'ny License. //SPDX-License-Identifier: MIT Massachusetts Institute of Technology (MIT) : Mamaritra fa nosoratana ho an'ny dikan-teny Solidity eo anelanelan'ny 0.8.0 (inclusive) sy 0.9.0 (exclusive) ny code. pragma solidity >=0.8.0 <0.9.0; State Variable uint256 public constant coffeePrice = 0.0002 ether; uint256 public totalCoffeesSold; uint256 public totalEtherReceived; : Apetraka ho sanda tsy miova amin'ny . coffeePrice 0.0002 ether : Manara-maso ny isan'ny kafe amidy. totalCoffeesSold : Manara-maso ny totalin'ny Etera voarain'ny fifanarahana. totalEtherReceived Fahadisoana manokana Ny hadisoana manokana ao amin'ny Solidity dia . Afaka manampy amin'ny fanatsarana ny traikefan'ny mpampiasa izy ireo, ary afaka manampy amin'ny debugging sy fitazonana fifanarahana marani-tsaina ihany koa. hafatra diso izay mifanaraka amin'ny tranga fampiasana manokana, fa tsy ny hafatra diso default izay omen'ny fiteny fandaharana Mba hamaritana hadisoana mahazatra ao amin'ny Solidity dia azonao ampiasaina ity syntax manaraka ity: : Ity teny fanalahidy ity dia ampiasaina hamaritana fahadisoana mahazatra error Anarana tokana: Ny hadisoana dia tsy maintsy manana anarana tokana Parametera: Raha te hampiditra antsipiriany na masontsivana manokana amin'ny hafatra diso ianao dia azonao ampidirina ao anaty fononteny aorian'ny anaran'ny hadisoana. error QuantityMustBeGreaterThanZero(); error InsufficientEtherSent(uint256 required, uint256 sent); error DirectEtherTransferNotAllowed(); : Miantoka fa mihoatra ny aotra ny isa. QuantityMustBeGreaterThanZero() : Miantoka fa ampy ny Etera nalefa. InsufficientEtherSent(uint256 required, uint256 sent) : Manakana ny famindrana mivantana ny Etera amin'ny fifanarahana. DirectEtherTransferNotAllowed() ZAVA-NITRANGA Ny hetsika dia ampahany amin'ny fifanekena mitahiry ny tohan-kevitra nandalo tao amin'ny diarin'ny fifampiraharahana rehefa navoaka. Ny hetsika dia matetika ampiasaina hampahafantarana ny fampiharana fiantsoana momba ny toetry ny fifanarahana amin'izao fotoana izao amin'ny fampiasana ny endri-tsoratry ny EVM. Mampandre ny fampiharana izy ireo momba ny fanovana natao tamin'ny fifanarahana, izay azo ampiasaina hampandehanana ny lojika mifandraika amin'izany. event CoffeePurchased(address indexed buyer, uint256 quantity, uint256 totalCost); : Fividianana kafe. CoffeePurchased(address indexed buyer, uint256 quantity, uint256 totalCost) asa Esorin'izy ireo ny famerana ny fanoratana indray ny kaody mitovy. Fa kosa, ny devs dia afaka miantso asa ao amin'ny programa rehefa ilaina izany. Functions dia modules misy kaody tokana izay mahavita asa manokana. function buyCoffee(uint256 quantity) external payable { if (quantity <= 0) { revert QuantityMustBeGreaterThanZero(); } uint256 totalCost = coffeePrice * quantity; if (msg.value > totalCost) { revert InsufficientEtherSent(totalCost, msg.value); } // Update the total coffees sold and total ether received totalCoffeesSold += quantity; totalEtherReceived += totalCost; console.log("Total ether received updated:", totalEtherReceived); console.log("Total coffee sold updated:", totalCoffeesSold); // Emit the purchase event emit CoffeePurchased(msg.sender, quantity, totalCost); // Refund excess Ether sent if (msg.value > totalCost) { uint256 refundAmount = msg.value - totalCost; payable(msg.sender).transfer(refundAmount); } } receive() external payable { revert DirectEtherTransferNotAllowed(); } function getTotalCoffeesSold() external view returns (uint256) { console.log("getTotalCoffeesSold :", totalCoffeesSold); return totalCoffeesSold; } function getTotalEtherReceived() external view returns (uint256) { console.log("getTotalEtherReceived :", totalEtherReceived); return totalEtherReceived; } : Mitantana ny fividianana kafe ary manao ireto asa manaraka ireto: buyCoffee(uint256 quantity) external payable Hamarino raha mitombina ny habetsahana. Kajy ny sarany manontolo. Miantoka ny fandefasana Etera ampy. Manavao ny fari-piainan'ny fanjakana. Mamoaka ny hetsika fividianana. Mamerina ny Etera tafahoatra. : Mamerina mivantana ny famindrana Ether raha misy mandefa vola mivantana amin'ny adiresin'ny fifanarahana. receive() external payable : Mamerina ny fitambaran'ny kafe amidy. getTotalCoffeesSold() external view returns (uint256) : Mamerina ny totalin'ny Etera voaray. getTotalEtherReceived() external view returns (uint256) Manangona ny fifanarahana Smart Payment Kafe Eto ianao dia hampiasa Hardhat hanangonana ny fifanarahana marani-tsaina. Mametraka Hardhat amin'ny fampiasana ity baiko manaraka ity. npm install --save-dev hardhat Hahazo ny valiny eto ambany ianao rehefa vita ny fametrahana. Ao amin'ny lahatahiry iray izay anombohanao hardhat amin'ny fampiasana ity baiko baiko ity: npx hardhat init Mifidiana Create a Javascript project amin'ny alàlan'ny fampiasana ny bokotra midina ary tsindrio ny Enter. Tsindrio ny Enter raha hametraka ao amin'ny lahatahiry faka Ekeo ny bitsika rehetra amin'ny fampiasana ny y amin'ny fitendry anao ao anatin'izany ny fiankinan'ny @nomicfoundation/hardhat-toolbox Hitanao ity valinteny eto ambany ity izay mampiseho fa nahomby ianao tamin'ny fanombohana Ho hitanao fa misy lahatahiry sy rakitra vaovao nampidirina ao amin'ny tetikasanao. ohatra, Lock.sol , iginition/modules , test/Lock.js ary hardhat.config.cjs . Aza manahy momba azy ireo. fampirimana fampirimana Ny hany mahasoa dia ny iginition/modules sy hardhat.config.cjs . Ho fantatrao ny ampiasana azy ireny any aoriana any. Aza misalasala mamafa Lock.sol eo ambanin'ny contracts sy Lock.js eo ambanin'ny iginition/modules . Angony ny fifanarahana amin'ny fampiasana ity baiko manaraka ity: npx hardhat compile Mahita lahatahiry sy rakitra fanampiny toa an'io ianao. rakitra Ao anatin'ny Coffee.json dia ny kaody ABI amin'ny endrika JSON izay hiantsoanao rehefa mifandray amin'ny fifanarahana marani-tsaina. { "_format": "hh-sol-artifact-1", "contractName": "Coffee", "sourceName": "contracts/coffee.sol", "abi": [ { "inputs": [], "name": "DirectEtherTransferNotAllowed", "type": "error" }, { "inputs": [ { "internalType": "uint256", "name": "required", "type": "uint256" }, { "internalType": "uint256", "name": "sent", "type": "uint256" } ], "name": "InsufficientEtherSent", "type": "error" }, { "inputs": [], "name": "QuantityMustBeGreaterThanZero", "type": "error" }, { "anonymous": false, "inputs": [ { "indexed": true, "internalType": "address", "name": "buyer", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "quantity", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "totalCost", "type": "uint256" } ], "name": "CoffeePurchased", "type": "event" }, { "inputs": [ { "internalType": "uint256", "name": "quantity", "type": "uint256" } ], "name": "buyCoffee", "outputs": [], "stateMutability": "payable", "type": "function" }, { "inputs": [], "name": "coffeePrice", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "getTotalCoffeesSold", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "getTotalEtherReceived", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "totalCoffeesSold", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "totalEtherReceived", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "stateMutability": "payable", "type": "receive" } ], "bytecode": "", "deployedBytecode": "", "linkReferences": {}, "deployedLinkReferences": {} } Fitsapana ny fifanarahana Smart Tena zava-dehibe sy tena ilaina ny manoratra sora-panadinana mandeha ho azy rehefa manorina ny fifanarahana marani-tsainao. Izy io dia miasa toy ny fanamarinana roa anton-javatra (2FA), miantoka fa ny fifanarahana marani-tsainao dia manatanteraka araka ny nantenaina alohan'ny handefasana azy amin'ny tambajotra mivantana. lahatahiry cjs. Apetaho ao anatin'ilay rakitra ity kaody ity: Eo ambanin'ny test dia mamorona rakitra vaovao, ary omeo anarana hoe Coffee. const { loadFixture } = require("@nomicfoundation/hardhat-toolbox/network-helpers.js"); const { expect } = require("chai"); const pkg = require("hardhat"); const ABI = require('../artifacts/contracts/coffee.sol/Coffee.json'); const { web3 } = pkg; describe("Coffee Contract", function () { // Fixture to deploy the Coffee contract async function deployCoffeeFixture() { const coffeeContract = new web3.eth.Contract(ABI.abi); coffeeContract.handleRevert = true; const [deployer, buyer] = await web3.eth.getAccounts(); const rawContract = coffeeContract.deploy({ data: ABI.bytecode, }); // Estimate gas for the deployment const estimateGas = await rawContract.estimateGas({ from: deployer }); // Deploy the contract const coffee = await rawContract.send({ from: deployer, gas: estimateGas.toString(), gasPrice: "10000000000", }); console.log("Coffee contract deployed to: ", coffee.options.address); return { coffee, deployer, buyer, rawContract }; } describe("Deployment", function () { // Test to check initial values after deployment it("Should set the initial values correctly", async function () { const { coffee } = await loadFixture(deployCoffeeFixture); const totalCoffeesSold = await coffee.methods.totalCoffeesSold().call(); const totalEtherReceived = await coffee.methods.totalEtherReceived().call(); expect(totalCoffeesSold).to.equal("0"); expect(totalEtherReceived).to.equal("0"); }); }); describe("Buying Coffee", function () { // Test to check coffee purchase and event emission it("Should purchase coffee and emit an event", async function () { const { coffee, buyer } = await loadFixture(deployCoffeeFixture); const quantity = 3; const totalCost = web3.utils.toWei("0.0006", "ether"); // Buyer purchases coffee const receipt = await coffee.methods.buyCoffee(quantity).send({ from: buyer, value: totalCost }); // Check event const event = receipt.events.CoffeePurchased; expect(event).to.exist; expect(event.returnValues.buyer).to.equal(buyer); expect(event.returnValues.quantity).to.equal(String(quantity)); expect(event.returnValues.totalCost).to.equal(totalCost); }); // Test to check revert when quantity is zero it("Should revert if the quantity is zero", async function () { const { coffee, buyer } = await loadFixture(deployCoffeeFixture); expect( coffee.methods.buyCoffee(0).send({ from: buyer, value: web3.utils.toWei("0.0002", "ether") }) ).to.be.revertedWith("QuantityMustBeGreaterThanZero"); }); // Test to check if totalCoffeesSold and totalEtherReceived are updated correctly it("Should update totalCoffeesSold and totalEtherReceived correctly", async function () { const { coffee, buyer } = await loadFixture(deployCoffeeFixture); const quantity = 5; const totalCost = web3.utils.toWei("0.001", "ether"); await coffee.methods.buyCoffee(quantity).send({ from: buyer, value: totalCost }); const totalCoffeesSold = await coffee.methods.totalCoffeesSold().call(); const totalEtherReceived = await coffee.methods.totalEtherReceived().call(); expect(totalCoffeesSold).to.equal(String(quantity)); expect(totalEtherReceived).to.equal(totalCost); }); }); describe("Fallback function", function () { // Test to check revert when ether is sent directly to the contract it("Should revert if ether is sent directly to the contract", async function () { const { coffee, buyer } = await loadFixture(deployCoffeeFixture); expect( web3.eth.sendTransaction({ from: buyer, to: coffee.options.address, value: web3.utils.toWei("0.001", "ether"), }) ).to.be.revertedWith("DirectEtherTransferNotAllowed"); }); }); }); Ity kaody ity dia mizaha toetra ny fiasan'ny fifanarahana smart Coffee. Tafiditra ao anatin'izany ny fitsapana amin'ny fametrahana, ny fividianana kafe ary ny fikarakarana ny famindrana mivantana amin'ny Ether amin'ny fifanarahana. Ity misy fizarazarana: Fixture Function: deployCoffeeFixture async function deployCoffeeFixture() { const coffeeContract = new web3.eth.Contract(ABI.abi); coffeeContract.handleRevert = true; const [deployer, buyer] = await web3.eth.getAccounts(); const rawContract = coffeeContract.deploy({ data: ABI.bytecode, }); const estimateGas = await rawContract.estimateGas({ from: deployer }); const coffee = await rawContract.send({ from: deployer, gas: estimateGas.toString(), gasPrice: "10000000000", }); console.log("Coffee contract deployed to: ", coffee.options.address); return { coffee, deployer, buyer, rawContract }; } : Mamorona ohatra fifanarahana vaovao ary mametraka izany amin'ny alàlan'ny kaontin'ny mpandefa. Mametraka ny fifanarahana Kafe : Tombanana ny entona ilaina amin'ny fametrahana. Tombanana entona : Ny kaontin'ny fifanekena, ny mpampiasa ary ny mpividy. Famerenana Fitsapana fandefasana describe("Deployment", function () { it("Should set the initial values correctly", async function () { const { coffee } = await loadFixture(deployCoffeeFixture); const totalCoffeesSold = await coffee.methods.totalCoffeesSold().call(); const totalEtherReceived = await coffee.methods.totalEtherReceived().call(); expect(totalCoffeesSold).to.equal("0"); expect(totalEtherReceived).to.equal("0"); }); }); : Miantoka fa sy dia napetraka ho aotra aorian'ny fametrahana azy. Manamarina ny sanda voalohany totalCoffeesSold totalEtherReceived Fividianana fitsapana kafe describe("Buying Coffee", function () { it("Should purchase coffee and emit an event", async function () { const { coffee, buyer } = await loadFixture(deployCoffeeFixture); const quantity = 3; const totalCost = web3.utils.toWei("0.0006", "ether"); const receipt = await coffee.methods.buyCoffee(quantity).send({ from: buyer, value: totalCost }); const event = receipt.events.CoffeePurchased; expect(event).to.exist; expect(event.returnValues.buyer).to.equal(buyer); expect(event.returnValues.quantity).to.equal(String(quantity)); expect(event.returnValues.totalCost).to.equal(totalCost); }); it("Should revert if the quantity is zero", async function () { const { coffee, buyer } = await loadFixture(deployCoffeeFixture); expect( coffee.methods.buyCoffee(0).send({ from: buyer, value: web3.utils.toWei("0.0002", "ether") }) ).to.be.revertedWith("QuantityMustBeGreaterThanZero"); }); it("Should update totalCoffeesSold and totalEtherReceived correctly", async function () { const { coffee, buyer } = await loadFixture(deployCoffeeFixture); const quantity = 5; const totalCost = web3.utils.toWei("0.001", "ether"); await coffee.methods.buyCoffee(quantity).send({ from: buyer, value: totalCost }); const totalCoffeesSold = await coffee.methods.totalCoffeesSold().call(); const totalEtherReceived = await coffee.methods.totalEtherReceived().call(); expect(totalCoffeesSold).to.equal(String(quantity)); expect(totalEtherReceived).to.equal(totalCost); }); }); : Fitsapana fa ny fividianana kafe dia manavao ny fanjakana ary mamoaka ny hetsika . Fividianana kafe sy famoahana hetsika CoffeePurchased : Miantoka ny fiverenan'ny fifampiraharahana raha aotra ny isa. Miverina amin'ny isa aotra : Manamarina fa sy dia nohavaozina araka ny tokony ho izy taorian'ny fividianana. Fanavaozana ny fanjakana araka ny tokony ho izy totalCoffeesSold totalEtherReceived Fallback Function Test describe("Fallback function", function () { it("Should revert if ether is sent directly to the contract", async function () { const { coffee, buyer } = await loadFixture(deployCoffeeFixture); expect( web3.eth.sendTransaction({ from: buyer, to: coffee.options.address, value: web3.utils.toWei("0.001", "ether"), }) ).to.be.revertedWith("DirectEtherTransferNotAllowed"); }); }); : Miantoka fa ny fandefasana an'i Etera mivantana amin'ny fifanarahana (tsy misy fiantsoana asa) dia mamerina ny fifampiraharahana. Miverina amin'ny famindrana mivantana Etera Fitsapana ny fifanarahana Smart Rehefa avy nanoratra ny script fitsapana ianao dia : Rehefa manatanteraka ny fifanarahanao sy ny fitsapana anao amin'ny Hardhat Network ianao dia afaka manonta hafatra logging sy fari-pifanarahana miantso console.log() avy amin'ny kaody Solidity anao. Raha hampiasa izany ianao dia tsy maintsy manafatra hardhat/console.sol amin'ny kaody fifanarahana toy izao: //SPDX-License-Identifier: MIT pragma solidity >=0.8.0 <0.9.0; import "hardhat/console.sol"; contract Coffee { //... } Mba hitsapana ny fifanarahana dia araho ity baiko manaraka ity ao amin'ny terminal anao: npx hardhat test Tokony hanana vokatra toy izao manaraka izao ianao: Izany dia mampiseho fa miasa araka ny nantenaina ny fifanarahana marani-tsainao. ianao Raha mihazakazaka npx hardhat test dia manangona ho azy ary andramo ny fifanarahana marani-tsaina. Azonao atao ny manandrana azy ary ampahafantaro ahy ao amin'ny sehatra fanehoan-kevitra. Fametrahana ny Smart Contract Eto ianao dia hametraka ny fifanarahana hendry anao amin'ny Testnet dia ahafahanao mitsapa ny fifanarahana marani-tsainao amin'ny tontolo iray izay maka tahaka ny mainnet Ethereum nefa tsy mandany vola be. Raha tsara amin'ny fiasan'ny dApp ianao, dia azonao atao ny mamerina amin'ny Ethereum Mainnet. Sepolia Testnet. Apetraho ny fonosana dotenv sy ireo fiankinana ireo. npm install dotenv npm install --save-dev @nomicfoundation/hardhat-web3-v4 'web3@4' Izany dia hanampy Web3.Js sy Dotenv amin'ny tetikasanao amin'ny fampidirana azy ao amin'ny lahatahiry 'node_modules'. izy ireo ampidiro ao amin'ny rakitra hardhat.config.cjs require('dotenv').config(); require("@nomicfoundation/hardhat-toolbox"); require("@nomicfoundation/hardhat-web3-v4"); const HardhatUserConfig = require("hardhat/config"); module.exports = { solidity: "0.8.24", } }; rakitra Mamorona .env ao amin'ny lahatahiry fakanao. Raiso ny lakilen'ny kaontinao manokana avy amin'ny kitapom-bola MetaMask sy ny lakilen'ny dRPC API. rakitra anao izy ireo Tehirizo ao amin'ny .env . DRPC_API_KEY=your_drpc_api_key PRIVATE_KEY=your_wallet_private_key rakitra Havaozy ny hardhat.config.cjs mba hampidirana ny Sepolia Testnet Configuration: require('dotenv').config(); require("@nomicfoundation/hardhat-toolbox"); require("@nomicfoundation/hardhat-web3-v4"); const HardhatUserConfig = require("hardhat/config"); const dRPC_API_KEY = process.env.VITE_dRPC_API_KEY; const PRIVATE_KEY = process.env.VITE_PRIVATE_KEY; module.exports = { solidity: "0.8.24", networks: { sepolia: { url: `https://lb.drpc.org/ogrpc?network=sepolia&dkey=${dRPC_API_KEY}`, accounts: [`0x${PRIVATE_KEY}`], } } }; fampirimana Mamorona rakitra script vaovao eo ambanin'ny ignition/module , ary omeo anarana hoe deploy.cjs . Ampio ity kaody manaraka ity mba hametrahana ny fifanarahana marani-tsainao: const { buildModule } = require("@nomicfoundation/hardhat-ignition/modules"); const CoffeeModule = buildModule("CoffeeModule", (m) => { const coffee = m.contract("Coffee"); return { coffee }; }); module.exports = CoffeeModule; Ampidiro ny fifanarahana smart amin'ny alàlan'ny fampandehanana ity baiko manaraka ity ao amin'ny terminal anao: npx hardhat ignition deploy ./ignition/modules/deploy.cjs --network sepolia Aorian'ny fampandehanana ny baikon'ny baiko dia angatahina ianao , soraty ny . Tokony ho hitanao ny adiresin'ny fifanarahana marani-tsaina napetrakao ao amin'ny terminal rehefa vita ny fametrahana. Confirm deploy to network sepolia (11155111)? (y/n) y Azonao atao ihany koa ny miditra amin'ny adiresin'ny fifanarahana ao amin'ny rakitra . deployed_addresses.json Arahabaina, nahomby tamin'ny fametrahanao ny fifanarahana hendry tamin'ny Sepolia Testnet ianao. 🎉 Famaranana Ity lahatsoratra ity dia nampianatra anao ny fomba hanoratana fifanarahana marani-tsaina momba ny fandoavam-bola, fitsapana, fanangonana ary fametrahana fifanarahana marani-tsaina mampiasa ny hardhat CLI. Ao amin'ny lahatsoratra manaraka dia hianatra ny hanangana ny faran'ny anoloana ho an'ity dApp ity ianao. Ity UI ity dia ahitana: Fampidirana saha ho an'ny isan'ny Kafe novidina. Bokotra miteraka fifampiraharahana fandoavam-bola ary manala izany amin'ny kaontinao. Asehoy ny Total kafe novidina sy ny vola azo amin'ny etera sy USD Ny vidin'ny Kafe mihitsy amin'ny etera sy USD. Reference Mihoatra ny Hafatra Default: Mifehy ny fahadisoana mahazatra amin'ny Solidity Fifehezana ny hadisoana mahazatra amin'ny fahamendrehana: Amboary ny fifanarahanao marani-tsaina mihoatra noho ny hafatra tsy mety Inona no atao hoe Solidity Functions? Inona no hetsika ao Solidity? ← Lahatsoratra teo aloha Lahatsoratra manaraka →