Zum Hauptinhalt springen
Plasma ist vollständig EVM-kompatibel, sodass Sie Standard-Ethereum-Tools verwenden und gleichzeitig von Funktionen profitieren können, die für stablecoin-native Anwendungen optimiert sind. Mehr zu den Architekturdetails von Plasma finden Sie im Abschnitt Architekturüberblick.

RPC-Konnektivität überprüfen

Öffentliche RPC-Endpunkte sind für beide Plasma-Netzwerke verfügbar:
# Mainnet (empfohlen)
curl --location https://rpc.plasma.to --header 'Content-Type: application/json' --data '{"method":"eth_blockNumber","params":[],"id":1,"jsonrpc":"2.0"}'

# Testnet (optional)
curl --location https://testnet-rpc.plasma.to --header 'Content-Type: application/json' --data '{"method":"eth_blockNumber","params":[],"id":1,"jsonrpc":"2.0"}'
Mainnet-Antworten sehen ähnlich aus wie:
{"jsonrpc":"2.0","id":1,"result":"0x11180f"}
Öffentliche Endpunkte sind rate-limitiert. Für den Produktionseinsatz oder hochfrequente Anfragen sollten Sie einen Partner-RPC-Anbieter in Betracht ziehen.

Entwicklungstools konfigurieren

Nachfolgend Beispiele für Hardhat und Truffle:

Hardhat

Erstellen oder bearbeiten Sie Ihre hardhat.config.js-Datei, um beide Plasma-Netzwerke aufzunehmen:
require("dotenv").config();

module.exports = {
  networks: {
    plasmaMainnet: {
      url: process.env.MAINNET_RPC_ENDPOINT || "https://rpc.plasma.to",
      chainId: 9745,
      accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : []
    },
    // Optional: enable the testnet for staging.
    plasmaTestnet: {
      url: process.env.TESTNET_RPC_ENDPOINT || "https://testnet-rpc.plasma.to",
      chainId: 9746,
      accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : []
    }
  },
  solidity: {
    version: "0.8.28",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200
      }
    }
  }
};

Truffle-Konfiguration

Wenn Sie Truffle verwenden, aktualisieren Sie Ihre truffle-config.js:
const HDWalletProvider = require('@truffle/hdwallet-provider');

module.exports = {
  networks: {
    plasmaMainnet: {
      provider: () => new HDWalletProvider(
        "<YOUR_MNEMONIC_HERE>",
        process.env.MAINNET_RPC_ENDPOINT || "https://rpc.plasma.to",
      ),
      network_id: 9745,
      gas: 5500000,
    },
    plasmaTestnet: {
      provider: () => new HDWalletProvider(
        "<YOUR_MNEMONIC_HERE>",
        process.env.TESTNET_RPC_ENDPOINT || "https://testnet-rpc.plasma.to",
      ),
      network_id: 9746,
      gas: 5500000,
    }
  },
  compilers: {
    solc: {
      version: "0.8.28",
      settings: {
        optimizer: {
          enabled: true,
          runs: 200
        }
      }
    }
  }
};

Wallet-Integration

Web3.js-Integration

const Web3 = require('web3');
const web3 = new Web3(process.env.MAINNET_RPC_ENDPOINT || 'https://rpc.plasma.to');

// Check connection
web3.eth.getBlockNumber()
  .then(blockNumber => console.log('Connected to Plasma node. Current block:', blockNumber))
  .catch(error => console.error('Connection error:', error));

Ethers.js-Integration

const { ethers } = require('ethers');
const provider = new ethers.JsonRpcProvider('https://testnet-rpc.plasma.to');

// Check connection
provider.getBlockNumber()
  .then(blockNumber => console.log('Connected to Plasma node. Current block:', blockNumber))
  .catch(error => console.error('Connection error:', error));

Einrichtung validieren

Erstellen Sie ein einfaches Skript, um zu überprüfen, ob Ihre Entwicklungsumgebung korrekt eingerichtet ist:
const { ethers } = require('ethers');
require('dotenv').config();

async function testSetup() {
  // Connect to the Plasma node.
  const provider = new ethers.JsonRpcProvider('https://testnet-rpc.plasma.to');
  
  // Get network information.
  const network = await provider.getNetwork();
  console.log('Connected to network:', network);
  
  // Get current block number.
  const blockNumber = await provider.getBlockNumber();
  console.log('Current block number:', blockNumber);
  
  // Optionally, print address and balance if PRIVATE_KEY is set.
  if (process.env.PRIVATE_KEY) {
    const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
    const balance = await provider.getBalance(wallet.address);
    console.log('Account address:', wallet.address);
    console.log('Balance:', ethers.formatEther(balance), 'XPL');
  } else {
    console.log('Set PRIVATE_KEY to also print address and balance.');
  }
}

testSetup()
  .then(() => console.log('Setup test completed successfully'))
  .catch(error => console.error('Setup test failed:', error));

Fehlerbehebung

ProblemAktion
Verbindung abgelehntBestätigen Sie, dass der RPC-Endpunkt korrekt und erreichbar ist
Gas-Schätzung fehlgeschlagenStellen Sie sicher, dass die Wallet ausreichend XPL hat
Solidity-VersionsfehlerAktualisieren Sie die Konfiguration auf die von Plasma unterstützte Compiler-Version
Transaktion schlägt fehlRPC-URL und korrekte Chain ID überprüfen