> ## Documentation Index
> Fetch the complete documentation index at: https://docs.plasma.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Schnellstart

> 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.

## Voraussetzungen

* Node.js 20+
* Grundkenntnisse zur Ethereum-Entwicklung
* Browser-Wallet

## Umgebungseinrichtung

Verwenden Sie Hardhat zum Bauen und Deployen von Verträgen.

### Hardhat-Einrichtung

1. Erstellen Sie ein neues Projektverzeichnis und initialisieren Sie:

   ```shell theme={null}
   mkdir my-plasma-project
   cd my-plasma-project
   npm init -y
   npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox
   npm install dotenv
   npx hardhat init
   ```
2. 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.
3. Konfigurieren Sie `hardhat.config.js` für das Plasma Testnet:

   ```javascript theme={null}
   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.
       }
     }
   };
   ```

## Wallet- & Testnet-Einrichtung

### Plasma Testnet zu Ihrer Browser-Wallet hinzufügen

1. Öffnen Sie Ihre Browser-Wallet (MetaMask, Trust Wallet oder Rabby) und klicken Sie auf die Netzwerkauswahl.
2. Wählen Sie die Option zum Hinzufügen eines benutzerdefinierten Netzwerks (z. B. **Netzwerk hinzufügen**, **Manuell hinzufügen** oder **Benutzerdefiniertes Netzwerk hinzufügen**).
3. 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`
4. Speichern Sie das Netzwerk und wechseln Sie in Ihrer Wallet zum Plasma Testnet.

### Testnet-Tokens erhalten

1. Kopieren Sie Ihre Wallet-Adresse aus Ihrer Browser-Wallet.
2. Besuchen Sie [openfaucet.org](https://openfaucet.org/).
3. Geben Sie Ihre Adresse ein und fordern Sie Testnet-Tokens an.
4. Warten Sie auf den Abschluss der Transaktion (sie sollte innerhalb weniger Sekunden in Ihrer Wallet erscheinen).

### Umgebungsvariablen einrichten

1. Exportieren Sie den privaten Schlüssel Ihres Kontos über die Kontoeinstellungen Ihrer Browser-Wallet.
2. Erstellen Sie eine `.env`-Datei im Projekt-Root:

   ```shell theme={null}
   PRIVATE_KEY=your_private_key_here
   RPC_ENDPOINT=https://testnet-rpc.plasma.to
   ```

<Warning>
  Committen Sie niemals Ihren privaten Schlüssel oder Mnemonic in die Versionskontrolle. Fügen Sie `.env` zu Ihrer `.gitignore`-Datei hinzu.
</Warning>

## Einen einfachen Smart Contract schreiben

1. Erstellen Sie einen einfachen Storage-Vertrag `contracts/SimpleStorage.sol`:

   ```solidity theme={null}
   // SPDX-License-Identifier: MIT
   pragma solidity ^0.8.28;

   contract SimpleStorage {
       string private storedData;
       
       event DataStored(string data);
       
       constructor() {
           storedData = "Hello, Plasma!";
       }
       
       function setData(string memory data) public {
           storedData = data;
           emit DataStored(data);
       }
       
       function getData() public view returns (string memory) {
           return storedData;
       }
   }
   ```
2. Kompilieren Sie den Vertrag:

   ```shell theme={null}
   npx hardhat compile
   ```

   Das sollte etwa Folgendes ausgeben:

   ```plaintext theme={null}
   Downloading compiler 0.8.28
   Downloading compiler 0.8.28
   Compiled 2 Solidity files successfully (evm target: paris).
   ```

## Tests

1. Erstellen Sie ein Testskript `test/SimpleStorage.js`:

   ```javascript theme={null}
   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");
     });
   });
   ```
2. Führen Sie die Tests aus:

   ```shell theme={null}
   npx hardhat test
   ```

   Das sollte etwa Folgendes ausgeben:

   ```plaintext theme={null}
   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 owner

   SimpleStorage
     ✔ Should return the initial greeting
     ✔ Should update the stored data


   11 passing (541ms)
   ```

### Auf Plasma Testnet deployen

1. Erstellen Sie zunächst ein `scripts`-Verzeichnis:

   ```shell theme={null}
   mkdir scripts
   ```
2. Erstellen Sie als Nächstes ein Skript zum Deployen des Vertrags `scripts/deploy.js`:

   ```javascript theme={null}
   async function main() {
     const SimpleStorage = await ethers.getContractFactory("SimpleStorage");
     
     console.log("Deploying SimpleStorage...");
     const simpleStorage = await SimpleStorage.deploy();
     await simpleStorage.waitForDeployment();
     
     const address = await simpleStorage.getAddress();
     console.log("SimpleStorage deployed to:", address);
   }

   main()
     .then(() => process.exit(0))
     .catch((error) => {
       console.error(error);
       process.exit(1);
     });
   ```
3. Deployen Sie den Vertrag:

   ```shell theme={null}
   npx hardhat run scripts/deploy.js --network plasmaTestnet
   ```

   Das sollte etwa Folgendes ausgeben:

   ```plaintext theme={null}
   Deploying SimpleStorage...
   SimpleStorage deployed to: 0xaa4FB2A8eD6953A4e57b8097BAf048d7919e6262
   ```
4. Notieren Sie sich die `deployed to:`-Adresse. Das ist die Adresse Ihres Vertrags im Plasma Testnet.

## Deployment überprüfen

1. Kopieren Sie die Vertragsadresse.
2. Besuchen Sie den [Plasma Testnet Explorer](https://testnet.plasmascan.to/).
3. Suchen Sie nach Ihrer Vertragsadresse, um die Deployment-Transaktion anzuzeigen.

## Fehlerbehebung

| Problem                   | Lösung                                                                                          |
| :------------------------ | :---------------------------------------------------------------------------------------------- |
| Gas-Schätzungsfehler      | Stellen Sie sicher, dass die Wallet ausreichend XPL hat                                         |
| Netzwerkverbindungsfehler | RPC-URL und Testnet-Verfügbarkeit überprüfen                                                    |
| Private-Key-Fehler        | Stellen Sie sicher, dass `.env` korrekt konfiguriert ist (kein `0x`-Präfix, falls erforderlich) |
| Explorer-Verzögerung      | Warten Sie einige Minuten; der Explorer synchronisiert möglicherweise                           |
