Contracts Deployment

Getting started contract deployment in Patex Network

This tutorial teaches you the basics of Patex development. Patex is EVM equivalent, meaning we run a slightly modified version of the same geth you run on mainnet. Therefore, the differences between Patex development and Ethereum development are minor.

Patex Network Description

MainnetParameters

Network name

Patex Network

RPC URL

Chain ID

789

Currency symbol

ETH

Block explorer URL

# Patex endpoint URL

Network choice

For development purposes we recommend you use either a local development node on Patex Sepolia Testnet. That way you don't need to spend real money. If you need ETH on Patex Sepolia for testing purposes, you can use this faucet.

# Interacting with Patex contracts

We have Hardhat's Greeter contract on Patex Sepolia, at address 0x317ccBB804c1f104b0fA1495B625c87F66091745. You can verify your development stack configuration by interacting with it.

As you can see in the different development stacks below, the way you deploy contracts and interact with them on Patex is almost identical to the way you do it with L1 Ethereum. The most visible difference is that you have to specify a different endpoint (of course).

# Development stacks

Hardhat

In Hardhat you use a configuration similar to this one.

Connecting to Patex

Follow these steps to add Patex Sepolia support to an existing Hardhat project (or a newly created one).

  1. Define your network configuration in .env:

    # Put the mnemonic for an account on Patex here
    MNEMONIC=test test test test test test test test test test test junk
    
    
    # URL to access Patex Sepolia 
    PATEX_SEPOLIA_URL=https://test-rpc.patex.io
  2. Add dotenv to your project:

  3. Edit hardhat.config.js:

    1. Use .env for your blockchain configuration:

      require('dotenv').config()
    2. Get the correct URL from the configuration:

      const patexSepoliaUrl = process.env.PATEX_SEPOLIA_URL
    3. Add a network definition in module.exports.networks:

      "patex-sepolia": {
         url: patexSepoliaUrl,
         accounts: { mnemonic: process.env.MNEMONIC }
      }    

Greeter interaction

  1. Run the console:

    cd hardhat
    yarn
    yarn hardhat console --network patex-sepolia
  2. Connect to the Greeter contract:

    Greeter = await ethers.getContractFactory("Greeter")
    greeter = await Greeter.attach("0x317ccBB804c1f104b0fA1495B625c87F66091745")
  3. Read information from the contract:

  4. Submit a transaction, wait for it to be processed, and see that it affected the state.

    tx = await greeter.setGreeting(`Hardhat: Hello ${new Date()}`)
    rcpt = await tx.wait()  
    await greeter.greet()

Deploying a contract

To deploy a contract from the Hardhat console:

Greeter = await ethers.getContractFactory("Greeter")
greeter = await Greeter.deploy("Greeter from hardhat")
console.log(`Contract address: ${greeter.address}`)
await greeter.greet()
Truffle

In Truffle you use a configuration similar to this one.

Connecting to Patex

Follow these steps to add Patex Sepolia support to an existing Truffle project.

  1. Define your network configuration in .env:

    # Put the mnemonic for an account on Patex here
    MNEMONIC=test test test test test test test test test test test junk
    
    # URL to access Patex Sepolia
    PATEX_SEPLOIA_URL=
  2. Add dotenv and @truffle/hdwallet-provider to your project:

    yarn add dotenv @truffle/hdwallet-provider
  3. Edit truffle-config.js:

    1. Uncomment this line:

      const HDWalletProvider = require('@truffle/hdwallet-provider')
    2. Use .env for your network configuration:

      require('dotenv').config()
    3. Get the correct URL:

      const patexSeploiaUrl = process.env.PATEX_SEPOLIA_URL
    4. Add a network definition in module.exports.networks:

      "patex-seploia": {
         provider: () => new HDWalletProvider(
            process.env.MNEMONIC,
            patexSeploiaUrl),
         network_id: 471100
      }

Greeter interaction

  1. Compile the contract and run the console.

    truffle compile
    truffle console --network patex-seploia
  2. Connect to the Greeter contact.

    greeter = await Greeter.at("0x317ccBB804c1f104b0fA1495B625c87F66091745")
  3. Read information from the contact.

  4. Submit a transaction.

    tx = await greeter.setGreeting(`Truffle: Hello ${new Date()}`)
  5. Wait a few seconds for the transaction to be processed.s

  6. See that the greeting has changed.

Contract deployment

You deploy a new contract from the console.

greeter = await Greeter.new("Greeter from Truffle")

Wait a few seconds for the deployment to actually happen and then verify.

console.log(`Contract address: ${greeter.address}`)
await greeter.greet()
Remix

Connecting to Patex

In Remix you access Patex through your own wallet.

  1. Add Patex Sepolia to your wallet.

  2. Log on with your wallet to Patex Seploia.

  3. Browse to Remix.

  4. Click the run icon ().

  5. Select the Environment Injected Provider - MetaMask.

  6. Accept the connection in the wallet.

Greeter interaction

  1. Click the run icon ().

  2. Make sure your environment is Injected Web3 and the network ID is 471100.

  3. Click the files icon ().

  4. Download Greeter.sol and upload () it to Remix under contracts.

  5. Right-click contracts > Greeter.sol and select Compile.

  6. Open contracts > artifacts and see that there's a Greeter.json file. This file is the compiled version, the API for the contract, etc.

  7. Click the run icon ().

  8. Scroll down. In the At Address field, type the contract address 0x317ccBB804c1f104b0fA1495B625c87F66091745. Then, click At Address. Expand the contract to see you can interact with it.

  9. Click greet and expand the transaction result in the console (bottom right).

  10. Type a greeting (preferably, one that starts with the word Remix) and then click setGreeting. Approve the transaction in your wallet. Note that if the greeting includes a comma you need to enclose it in quotes.

  11. See the results on the console and then click greet again to see the greeting changed (see it under the greet button).

Contract deployment

You deploy a new contract:

  1. Type a string for the greeter.

  2. Click Deploy.

  3. Confirm the transaction in the wallet.

# Best practices

It is best to start development with the EVM provided by the development stack. Not only is it faster, but such EVMs often have extra features, such as the ability to log messages from Solidity or a graphical user interface.

After you are done with that development, debug your decentralized application using either the Sepolia test network. This lets you debug parts that are Patex specific such as calls to bridges to transfer assets between layers.

Only when you have a version that works well on a test network should you deploy to the production network, where every transaction has a cost.

Contract source verification

You don't have to upload your source code to block explorers, but it is a good idea. On the test network it lets you issue queries and transactions from the explorer's user interface. On the production network it lets users know exactly what your contract does, which is conducive to trust.

Just remember, if you use the Patexscan API, you need one API key for Patex and a separate one for Patex Sepolia.

Last updated