当前位置: 首页 > 工具软件 > Ethermint > 使用案例 >

ethermint部署智能合约

诸修伟
2023-12-01

ethermint部署智能合约

安装ethermint

  1. 获取ethermint源码,并安装

git clone https://github.com/cosmos/ethermint.git 

cd ethermint 

make install

  • 检查是否安装成

cd $GOPATH/bin

ll ethermint*

ethermintd

ethermin俄cli

  • 将GOPATH/bin加入到PATH环境变量

export PATH=$PATH:$GOPATH/bin

启动ethermintd

  • 启动脚本

#!/bin/bash

KEY="mykey"
CHAINID="ethermint-1"
MONIKER="localtestnet"

# remove existing daemon and client
rm -rf ~/.ethermint*

make install

ethermintcli config keyring-backend test

# Set up config for CLI
ethermintcli config chain-id $CHAINID
ethermintcli config output json
ethermintcli config indent true
ethermintcli config trust-node true

# if $KEY exists it should be deleted
ethermintcli keys add $KEY

# Set moniker and chain-id for Ethermint (Moniker can be anything, chain-id must be an integer)
ethermintd init $MONIKER --chain-id $CHAINID

# Change parameter token denominations to aphoton
cat $HOME/.ethermintd/config/genesis.json | jq '.app_state["staking"]["params"]["bond_denom"]="aphoton"' > $HOME/.ethermintd/config/tmp_genesis.json && mv $HOME/.ethermintd/config/tmp_genesis.json $HOME/.ethermintd/config/genesis.json
cat $HOME/.ethermintd/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="aphoton"' > $HOME/.ethermintd/config/tmp_genesis.json && mv $HOME/.ethermintd/config/tmp_genesis.json $HOME/.ethermintd/config/genesis.json
cat $HOME/.ethermintd/config/genesis.json | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="aphoton"' > $HOME/.ethermintd/config/tmp_genesis.json && mv $HOME/.ethermintd/config/tmp_genesis.json $HOME/.ethermintd/config/genesis.json
cat $HOME/.ethermintd/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="aphoton"' > $HOME/.ethermintd/config/tmp_genesis.json && mv $HOME/.ethermintd/config/tmp_genesis.json $HOME/.ethermintd/config/genesis.json

# Enable faucet
cat $HOME/.ethermintd/config/genesis.json | jq '.app_state["faucet"]["enable_faucet"]=true' > $HOME/.ethermintd/config/tmp_genesis.json && mv $HOME/.ethermintd/config/tmp_genesis.json $HOME/.ethermintd/config/genesis.json

# Allocate genesis accounts (cosmos formatted addresses)
ethermintd add-genesis-account $(ethermintcli keys show $KEY -a) 100000000000000000000aphoton

# Sign genesis transaction
ethermintd gentx --name $KEY --amount=1000000000000000000aphoton --keyring-backend test

# Collect genesis tx
ethermintd collect-gentxs

echo -e '\n\ntestnet faucet enabled'
echo -e 'to transfer tokens to your account address use:'
echo -e "ethermintcli tx faucet request 100aphoton --from $KEY\n"


# Run this to ensure everything worked and that the genesis file is setup correctly
ethermintd validate-genesis

# Command to run the rest server in a different terminal/window
echo -e '\nrun the following command in a different terminal/window to run the REST server and JSON-RPC:'
echo -e "ethermintcli rest-server --laddr \"tcp://localhost:8545\" --unlock-key $KEY --chain-id $CHAINID --trace\n"

# Start the node (remove the --pruning=nothing flag if historical queries are not needed)
ethermintd start --pruning=nothing --rpc.unsafe --log_level "main:info,state:info,mempool:info" --trace
  • 启动

./init.sh

........

........

I[2020-11-04|08:59:38.637] starting ABCI with Tendermint                module=main 

I[2020-11-04|08:59:38.703] Starting Mempool service                     module=mempool impl=Mempool

I[2020-11-04|08:59:43.754] Executed block                               module=state height=1 validTxs=0 invalidTxs=0

I[2020-11-04|08:59:43.760] Committed state                              module=state height=1 txs=0 appHash=F1F5B49BD9B2BE96ADDEBFABDB4D61448F2CF318531F48A365B3CAE85AFC079B

I[2020-11-04|08:59:48.791] Executed block                               module=state height=2 validTxs=0 invalidTxs=0

I[2020-11-04|08:59:48.796] Committed state                              module=state height=2 txs=0 appHash=403854C1560D0FD0C440A178FFBF43C0B1A286E13045DD7500F904293B3268A4

I[2020-11-04|08:59:53.834] Executed block                               module=state height=3 validTxs=0 invalidTxs=0

I[2020-11-04|08:59:53.839] Committed state                              module=state height=3 txs=0 appHash=BF5C00A80CA84A19C8E59281BD8708D062A21AEB4EBBB17AC23E05CFADB1E7C3

运行ethermintcli

ethermintcli rest-server --laddr "tcp://localhost:8545" --unlock-key mykey --chain-id ethermint-1 --trace


└─(09:03:45 on development ✹)──> ethermintcli rest-server --laddr "tcp://localhost:8545" --unlock-key mykey --chain-id ethermint-1 --trace 

I[2020-11-04|09:03:47.577] Starting application REST service (chain-id: "ethermint-1")... module=rest-server 

I[2020-11-04|09:03:47.577] Starting RPC HTTP server on 127.0.0.1:8545   module=rest-server 

部署ethermint-deploy

  • 获取源码

git clone https://github.com/ChainSafe/ethermint-deploy.git

  • 安装 & 运行

cd ethermint-deploy

yarn install

........

└─(09:10:30 on master)──> yarn start

yarn run v1.22.5

$ node ./web3/deploy_contract.js

Compiling contract code...

Unlocked account address:      0x23968ffE1374651fAa74f97e4603cf575C300719

Deploying contract...

Deployed contract Address:      0xeEB5166666429b817A05ac35DCda5cdB13399c6D

Counter pre increment is:      0

Sending add transaction...

Add tx finalized in block:      134

Counter post increment is:      1

Done in 10.07s.

 类似资料: