Go-Ethereum

如何創建本地 USDT 測試網?

  • October 4, 2021

我想創建一個本地測試網,我可以在其上在錢包之間移動 USDT(測試幣)。

我設法在 Docker 中創建了一個 ETH 測試網。在docker-compose.yml下面, 和 之間的線# ETH testnet setup (start)負責# ETH testnet setup (end)

version: '3'

services:
#
# BTC testnet setup (start)
#
 node:
   image: ulamlabs/bitcoind-custom-regtest:latest
 electrumx:
   image: lukechilds/electrumx:latest
   links:
     - node
   ports:
     - "51001:50001"
     - "51002:50002"
   environment:
     - NET=regtest
     - COIN=BitcoinSegwit
     - DAEMON_URL=http://test:test@node:19001
 explorer:
   image: ulamlabs/btc-rpc-explorer:latest
   links:
     - node
     - electrumx
   ports:
     - "3002:3002"
   environment:
     - BTCEXP_HOST=0.0.0.0
     - BTCEXP_BITCOIND_URI=http://test:test@node:19001
     - BTCEXP_ELECTRUMX_SERVERS=tls://electrumx:50002
     - BTCEXP_ADDRESS_API=electrumx
#
# BTC testnet setup (end)
#


#
# ETH testnet setup (start)
#
 geth:
   image: ulamlabs/geth-poa-testnet:latest
   environment:
     - ETH_PASSWORD=QfdxTYxkwASj
     - ETH_PRIVATE_KEY=0d0b4c455973c883bb0fa584f0078178aa90c571a8f1d40f28d2339f4e757dde
     - ETH_ADDRESS=0c56352F05De44C9b5BA8bcF9BDEc7e654993339
   ports:
     - 8178:8178
     - 8546:8546
   volumes:
     - ./genesis.json:/app/genesis.json

 postgres:
   image: postgres:12
   command: postgres -c 'max_connections=500'
   environment:
     - POSTGRES_HOST_AUTH_METHOD=trust

 blockscout:
   image: ulamlabs/blockscout:latest
   links:
     - geth
     - postgres
   ports:
     - 4000:4000
   environment:
     - DATABASE_URL=postgresql://postgres:@postgres:5432/postgres?ssl=false
     - ETHEREUM_JSONRPC_VARIANT=geth
     - ETHEREUM_JSONRPC_HTTP_URL=http://geth:8178
     - ETHEREUM_JSONRPC_WS_URL=ws://geth:8546
     - MIX_ENV=prod
     - BLOCKSCOUT_HOST=localhost
     - COIN=eth
     - NETWORK=POA
     - SUBNETWORK=Local Testnet

#
# ETH testnet setup (end)
#

該文件./genesis.json:/app/genesis.json包含以下內容:

{
   "config": {
       "chainId": 5555,
       "clique": {
           "period": 60,
           "epoch": 30000
       },
       "homesteadBlock": 0,
       "eip150Block": 0,
       "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
       "eip155Block": 0,
       "eip158Block": 0,
       "byzantiumBlock": 0,
       "constantinopleBlock": 0,
       "petersburgBlock": 0,
       "istanbulBlock": 0,
       "muirGlacierBlock": 0
   },
   "extraData": "0x00000000000000000000000000000000000000000000000000000000000000000c56352F05De44C9b5BA8bcF9BDEc7e6549933390000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
   "alloc": {
       "411167FeFecAD12Da17F9063143706C39528aa28": {
           "balance": "0x200000000000000000000000000000000000000000000000000000000000000"
       }
   },
   "nonce": "0x0",
   "timestamp": "0x5eaa7b09",
   "gasLimit": "0x47b760",
   "difficulty": "0x1",
   "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
   "coinbase": "0x0000000000000000000000000000000000000000",
   "number": "0x0",
   "gasUsed": "0x0",
   "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}

據我所理解,

  • 此測試網中沒有開採任何 USDT 測試幣,並且
  • 為了讓 USDT 測試硬幣,我需要向 ETH (geth) 測試網添加 ERC20 支持。

我需要如何修改上述docker-compose.yml和/或genesis.json文件才能將 ERC20/USDT 支持添加到我的 ETH 測試網?

我會盡力回答,儘管這個問題對我來說不是 100% 清楚。

乙太坊轉賬

賬戶之間的乙太幣轉移由區塊鏈本地處理。您無需部署任何智能合約即可執行此操作。

ERC-20 傳輸

USDT 和其他 ERC-20 代幣本身並不存在於區塊鏈上。每個 ERC-20 代幣都是由某人部署的智能合約。例如,是 USDT 合約地址。您也可以在此處閱讀 USDT 合約程式碼。

USDT 是一個測試網

要回答您的問題,您可以通過在該測試網上部署 USDT 合約(如上鍊接)的精確副本,然後transfer()在智能合約上呼叫一些函式,在測試網上測試 USDT。

請注意,您不需要創建自己的測試網。您可以使用 Ropsten、Kovan、Rinkeby 等公共測試網。您還可以使用 ganache-cli 等工具對乙太坊主網進行本地分叉。對於後者,USDT 合約已經部署,你可以在乙太坊主網的本地分支上對其進行測試。Ganache-cli還允許您非常輕鬆地創建本地測試網。

引用自:https://ethereum.stackexchange.com/questions/110684