Richten Sie Ihre Umgebung ein und deployen Sie einen Vertrag auf das Plasma Testnet mit Hardhat oder Foundry.
Dieser Leitfaden behandelt Umgebungseinrichtung, Vertrags-Deployment und Interaktion mit Plasmas EVM-kompatiblem Testnet unter Verwendung von Hardhat. Grundkenntnisse zu Ethereum-Tools und Smart-Contract-Entwicklung werden vorausgesetzt.
Folgen Sie den Schritten, um ein JavaScript-Projekt zu erstellen. Speichern Sie das Projekt, wo Sie möchten. Sie benötigen wahrscheinlich keine .gitignore-Datei für diesen Schnellstart.
Konfigurieren Sie hardhat.config.js für das Plasma Testnet:
require("@nomicfoundation/hardhat-toolbox");require("dotenv").config();/** @type import('hardhat/config').HardhatUserConfig */module.exports = { solidity: "0.8.28", networks: { plasmaTestnet: { url: process.env.RPC_ENDPOINT, chainId: 9746, accounts: [process.env.PRIVATE_KEY] // We'll set this up next. } }};
Öffnen Sie Ihre Browser-Wallet (MetaMask, Trust Wallet oder Rabby) und klicken Sie auf die Netzwerkauswahl.
Wählen Sie die Option zum Hinzufügen eines benutzerdefinierten Netzwerks (z. B. Netzwerk hinzufügen, Manuell hinzufügen oder Benutzerdefiniertes Netzwerk hinzufügen).
Geben Sie diese Details ein:
Netzwerkname: Plasma Testnet
Neue RPC-URL: https://testnet-rpc.plasma.to
Chain ID: 9746
Währungssymbol: XPL
Block-Explorer-URL: https://testnet.plasmascan.to
Speichern Sie das Netzwerk und wechseln Sie in Ihrer Wallet zum Plasma Testnet.
Erstellen Sie ein Testskript test/SimpleStorage.js:
const { expect } = require("chai");describe("SimpleStorage", function () { let simpleStorage; beforeEach(async function () { const SimpleStorage = await ethers.getContractFactory("SimpleStorage"); simpleStorage = await SimpleStorage.deploy(); await simpleStorage.waitForDeployment(); }); it("Should return the initial greeting", async function () { expect(await simpleStorage.getData()).to.equal("Hello, Plasma!"); }); it("Should update the stored data", async function () { await simpleStorage.setData("Updated data"); expect(await simpleStorage.getData()).to.equal("Updated data"); });});
Führen Sie die Tests aus:
npx hardhat test
Das sollte etwa Folgendes ausgeben:
Lock Deployment ✔ Should set the right unlockTime (454ms) ✔ Should set the right owner ✔ Should receive and store the funds to lock ✔ Should fail if the unlockTime is not in the future Withdrawals Validations ✔ Should revert with the right error if called too soon ✔ Should revert with the right error if called from another account ✔ Shouldn't fail if the unlockTime has arrived and the owner calls it Events ✔ Should emit an event on withdrawals Transfers ✔ Should transfer the funds to the ownerSimpleStorage ✔ Should return the initial greeting ✔ Should update the stored data11 passing (541ms)