Quick Migration For Ethereum[Bounty #191]

PlatON is now fully compatible with Ethereum, meaning that smart contracts on Ethereum can be deployed directly on PlatON via platon-truffle, and contract bytecodes running on Ethereum can also be deployed directly on PlatON. To make it easier, more efficient, and less costly for Ethereum users to migrate to PlatON, we chose to migrate directly using Ethereum development tools.

PlatON Network Information

**Website:**PlatON

**Dev docs:**Overview | PlatON

**Token Symbol:**LAT

Mainnet

Public RPC:https://openapi.platon.network/rpc

Chain id: 100

Block explorer:https://scan.platon.network/

Dev Network

public RPC:http://35.247.155.162:6789

Chain id: 210309

Block explorer:https://devnetscan.platon.network/

Faucet:PlatON

Preparation

Create PlatON Accounts

Since Ethereum and PlatON use the same encryption algorithm, we can use ethereum accounts directly.

If you need to create a new account, there are many ways to do so, such as using Metamask or using the PlatON official wallet ATON, which supports PlatON, PlatON Dev, and Alaya networks. ATON wallet download address: PlatON.

It’s important to note that Bech32 encoding is used for PlatON address, we can convert it to hex address in the browser https://scan.platon.network/.11760×256 14.5 KB21745×251 14.6 KB

Get token

PlatON Dev token can be got from faucet, address of which is: PlatON.

Mainnet tokens can be purchased through exchanges, transferred by others, or earned by participating in events.

Here we take Truffle and Remix as examples to illustrate the two development tools. Although other tools are used in different ways, their ideas are the same.

Migration

With Project Information

This migration works for all Ethereum projects, including Ethereum compatible projects, as long as you have complete engineering information for that project. It is important to note that the migration in this tutorial refers to the smart contract part and does not include the off-chain part, which is different for each project and needs to be handled separately.

The solution is very simple, summarized in the following three steps:

1.Modify Deployment Network

Replace the Ethereum network information with PlatON network information.

2.Modify Deployment Account

Replace the Ethereum account you originally used with the PlatON account you signed up for in preparation, and skip this step if you’re using the same key.

3.Deploy

Deploy as the original Ethereum deployment method.

Next, we will illustrate the following migration process using Truffle and Remix, respectively

Truffle

A world class development environment, testing framework and asset pipeline for blockchains using the Ethereum Virtual Machine (EVM), aiming to make life as a developer easier.

Website:https://trufflesuite.com/

Modify Deployment Network

Add the following configuration information to truffle-config.js

platonDev: {
    provider: () => new HDWalletProvider(mnemonic, ‘http://35.247.155.162:6789’),
    network_id: "*",    // Any network (default: none)
},
platon: {
    provider: () => new HDWalletProvider(mnemonic, ’https://openapi.platon.network/rpc‘),
    network_id: "*",    // Any network (default: none)
},

Modify Deployment Account

We need to use the account private key with tokens.

Deploy

truffle migrate --network platon

If you are using PlatON Dev, change the command to

truffle migrate --network platonDev

Remix

Remix IDE is an open source web and desktop application. It fosters a fast development cycle and has a rich set of plugins with intuitive GUIs. Remix is used for the entire journey of contract development as well as act as a playground for learning and teaching Ethereum.

Website:https://remix.ethereum.org

Modify Deployment Network

Add PlatON network to metamask. PlatON Network information is shown above, and you can find detailed tutorial

Modify Deployment Account

Change the Remix linked account to the account with token that we prepared in the preparation work.

Deploy

Select Injected Web3 in the ENVIRONMENT of the Deploy & Run Transactions page, connect to the PlatON wallet account, and Deploy as what you did before.

That’s all. You read that right. The migration process is over here. If you have complete project information, it will be very easy to migrate your project to PlatON.

Without Project Information

If you don’t have project engineering information, for example if you want to migrate someone else’s project and you don’t have project engineering information, only the contract code found in Etherscan can be used, you can use this scheme. You can also use this scheme if you want to develop new contracts.

Truffle

Install

npm install -g truffle

After the installation is complete, you can view the command by typing truffle –help on the console

Create Truffle Project

Create a working directory, for example

mkdir myworkspace

Initialize the Truffle project

truffle init
npm init

Set Up The Network

Add PlatON network configuration in truffle-config.js.

The configuration is as follows

platonDev: {
    provider: () => new HDWalletProvider(mnemonic, ‘http://35.247.155.162:6789’),
    network_id: "*",    // Any network (default: none)
},
platon: {
    provider: () => new HDWalletProvider(mnemonic, ’https://openapi.platon.network/rpc‘),
    network_id: "*",    // Any network (default: none)
},

HDWalletProvider is a package provided by Truffle

const HDWalletProvider = require('@truffle/hdwallet-provider');

In order to use this package, you must first install it in your working directory

npm install @truffle/hdwallet-provider

You can directly use the private key for mnemonic, for security we put the private key file in the local, obtain as follows

const fs = require('fs');
const mnemonic = fs.readFileSync(".secret").toString().trim();

Migrate

Create a new deployment file in the Migrations directory in the format of 1_initial_migration.js to deploy the contract to the corresponding network

const Migrations = artifacts.require("Migrations");

module.exports = function (deployer) {
 	deployer.deploy(Migrations);
};

Enter the following command to deploy

truffle migrate --network platon

Demo

We use the Chainlink contract code migration as an example to illustrate the project migration with project information. Using Truffle, the environment installation process described above, you will find that the contract migration is really very simple.

Download code

git clone https://github.com/smartcontractkit/truffle-starter-kit.git

Install

npm install

Configure network

Add to truffle-config.js file

platonDev: {
    provider: () => new HDWalletProvider(mnemonic, ‘http://35.247.155.162:6789’),
    network_id: "*",    // Any network (default: none)
},
platon: {
    provider: () => new HDWalletProvider(mnemonic, ’https://openapi.platon.network/rpc‘),
    network_id: "*",    // Any network (default: none)
},

Create private key file

echo <PRIVATE_KEY> >> .env

is the private key you use to deploy the contract

Deploy

An error will occur during deployment because the OpenZeppelin library version is too high, so we’ll just use the lower version and execute the following code

npm install @openzeppelin/contracts@3.3.0

Execute deployment command

truffle migrate --network platonDev

The following is part of the printed information

2_mycontract_migration.js
=========================

Replacing 'LinkToken'
---------------------

   > transaction hash:    0xbcfc948455e0ef210540230b4cd807d21f83847c95da2f8542ec892738b26648
   > Blocks: 2            Seconds: 4
   > contract address:    0xE49d98103e90F801C34D06879aF03da7F55f6c8C
   > block number:        14478621
   > block timestamp:     1646578668241
   > account:             0x30ad2981E83615001fe698b6fBa1bbCb52C19Dfa
   > balance:             292.628332679
   > gas used:            764685 (0xbab0d)
   > gas price:           50 gwei
   > value sent:          0 ETH
   > total cost:          0.03823425 ETH


   Replacing 'Oracle'
   ------------------

   > transaction hash:    0xeaf84486dd5e26ab3317977a1025addbab0932e4e53b4dd772fb28cd52bfb098
   > Blocks: 5            Seconds: 4
   > contract address:    0x3b4Ec74590Cb011Cdc643d3A24C3d6a2bE98935A
   > block number:        14478626
   > block timestamp:     1646578673759
   > account:             0x30ad2981E83615001fe698b6fBa1bbCb52C19Dfa
   > balance:             292.554940129
   > gas used:            1467851 (0x1665cb)
   > gas price:           50 gwei
   > value sent:          0 ETH
   > total cost:          0.07339255 ETH


   Deploying 'MyContract'
   ----------------------

   > transaction hash:    0x354f28b3a200729bc0842093b6107a9320fa2d24a016737ae18721ccfae4064c
   > Blocks: 3            Seconds: 4
   > contract address:    0x8b0036b85C39a6bFB5768718bEF958415bBCd9B5
   > block number:        14478629
   > block timestamp:     1646578677071
   > account:             0x30ad2981E83615001fe698b6fBa1bbCb52C19Dfa
   > balance:             292.470083729
   > gas used:            1697128 (0x19e568)
   > gas price:           50 gwei
   > value sent:          0 ETH
   > total cost:          0.0848564 ETH

   > Saving migration to chain.
   >
   > Saving artifacts
   > -------------------------------------
   >
   > Total cost:           0.1964832 ETH

The deployed contract information can be found in the block browser, indicating that our migration has been successful.

Of course, Chainlink is a multifunctional project, and this section of code does not cover all of the migration work, just as an example.

For project migrations without engineering information, this should not be very common. If necessary check the official Uniswap migration.

This article is reproduced from https://forum.latticex.foundation/t/topic/6078

(0)
PlatONWorld-M6的头像PlatONWorld-M6Official
上一篇 7 3 月, 2022 10:43
下一篇 8 3 月, 2022 11:26

相关推荐

发表回复

登录后才能评论