SolidityやGeth,solcをいれてRimixのクラウドIDEを開いてみた


![Solidity.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/7103/a2fdee3a-7df0-7310-3fd4-e31c5c74f30c.png)

「[霊園ガイド](https://reien.top/)」サイト開発日記の高橋です。＜誰も知らんがな＜枕詞

最近は [ethers.js](https://qiita.com/toshirot/items/69962db92e5c6ee01b29) や [web3.js](https://qiita.com/toshirot/items/bbab6a407c333555715d) を眺めてる日々ですが、今日は、Ethereumのコントラクトを書くためのSolidityを入れてみます。

>Solidityとは、スマートコントラクトを記述するための手続き型プログラミング言語であり、キャビン・ウッドによって作成された。JavaSriptやC++に似た構文を持つとされる。SolidityによってコンパイルしたプログラムはEthereum Virtual Machine上での実行が想定されている。 ウィキペディア

ちなみに
Solidityのドキュメントはここにあります
https://docs.soliditylang.org/
Gethのドキュメント
https://geth.ethereum.org/docs/
Solidityコンパイラ（solc）のドキュメント
https://solidity-jp.readthedocs.io/ja/latest/using-the-compiler.html
Rimixのドキュメント
https://remix-ide.readthedocs.io/en/latest/

先人@kagami-r0927氏のページにUbuntu,Win,Macのインストール手順がまとまっていたので、そのUbuntu編を参考にさせてもらいながら、やってみます。
> Ethereum [Solidity 開発環境準備] 
https://qiita.com/kagami-r0927/items/1c24a8b461ac4a6396a8 #Qiita @diligent_appより 

### まずは Gethのインストール
いくつかあるEthereumクライアントの中で公式推奨されているクライアントGethを入れます。
```shell
sudo add-apt-repository -y ppa:ethereum/ethereum
```
今回の環境は [web3.js](https://qiita.com/toshirot/items/bbab6a407c333555715d) の時にAWSにさらのUbuntuを入れたので、add-apt-repositoryが入ってない、ということで、先にそれをインストールしました。
```shell
#add-apt-repositoryを入れる
sudo apt install software-properties-common
#リポジトリを追加する
sudo add-apt-repository -y ppa:ethereum/ethereum
#aptをアップデートする
sudo apt update
#ethereumをインストールするとGethも入る
sudo apt install ethereum
```
先人はapt-getを使われてますが、ここではいまどきのaptで行きます。
さて、geth --helpを打ってずらずらと以下のヘルプが出てくればOK。

一応、helpを眺めるために出力を全部貼っておきます。
```shell
geth --help

NAME:
   geth - the go-ethereum command line interface
   Copyright 2013-2022 The go-ethereum Authors
USAGE:
   geth [options] [command] [command options] [arguments...]
   
VERSION:
   1.10.17-stable-25c9b49f
   
COMMANDS:
   account                            Manage accounts
   attach                             Start an interactive JavaScript environment (connect to
 node)
   console                            Start an interactive JavaScript environment
   db                                 Low level database operations
   dump                               Dump a specific block from storage
   dumpconfig                         Show configuration values
   dumpgenesis                        Dumps genesis block JSON configuration to stdout
   export                             Export blockchain into file
   export-preimages                   Export the preimage database into an RLP stream
   import                             Import a blockchain file
   import-preimages                   Import the preimage database from an RLP stream
   init                               Bootstrap and initialize a new genesis block
   js                                 Execute the specified JavaScript files
   license                            Display license information
   makecache                          Generate ethash verification cache (for testing)
   makedag                            Generate ethash mining DAG (for testing)
   removedb                           Remove blockchain and state databases
   show-deprecated-flags              Show flags that have been deprecated
   snapshot                           A set of commands based on the snapshot
   version                            Print version numbers
   version-check                      Checks (online) whether the current version suffers fro
m any known security vulnerabilities
   wallet                             Manage Ethereum presale wallets
   help, h                            Shows a list of commands or help for one command
   
ETHEREUM OPTIONS:
  --config value                      TOML configuration file
  --datadir value                     Data directory for the databases and keystore (default:
 "/home/info/.ethereum")
  --datadir.ancient value             Data directory for ancient chain segments (default = in
side chaindata)
  --datadir.minfreedisk value         Minimum free disk space in MB, once reached triggers au
to shut down (default = --cache.gc converted to MB, 0 = disabled)
  --keystore value                    Directory for the keystore (default = inside the datadi
r)
  --usb                               Enable monitoring and management of USB hardware wallet
s
  --pcscdpath value                   Path to the smartcard daemon (pcscd) socket file (defau
lt: "/run/pcscd/pcscd.comm")
  --networkid value                   Explicitly set network id (integer)(For testnets: use -
-ropsten, --rinkeby, --goerli instead) (default: 1)
  --mainnet                           Ethereum mainnet
  --goerli                            Görli network: pre-configured proof-of-authority test n
etwork
  --rinkeby                           Rinkeby network: pre-configured proof-of-authority test
 network
  --ropsten                           Ropsten network: pre-configured proof-of-work test netw
ork
  --sepolia                           Sepolia network: pre-configured proof-of-work test netw
ork
  --kiln                              Kiln network: pre-configured proof-of-work to proof-of-
stake test network
  --syncmode value                    Blockchain sync mode ("snap", "full" or "light") (defau
lt: snap)
  --exitwhensynced                    Exits after block synchronisation completes
  --gcmode value                      Blockchain garbage collection mode ("full", "archive") 
(default: "full")
  --txlookuplimit value               Number of recent blocks to maintain transactions index 
for (default = about one year, 0 = entire chain) (default: 2350000)
  --ethstats value                    Reporting URL of a ethstats service (nodename:secret@ho
st:port)
  --identity value                    Custom node name
  --lightkdf                          Reduce key-derivation RAM & CPU usage at some expense o
f KDF strength
  --eth.requiredblocks value          Comma separated block number-to-hash mappings to requir
e for peering (<number>=<hash>)
  
LIGHT CLIENT OPTIONS:
  --light.serve value                 Maximum percentage of time allowed for serving LES requ
ests (multi-threaded processing allows values over 100) (default: 0)
  --light.ingress value               Incoming bandwidth limit for serving light clients (kil
obytes/sec, 0 = unlimited) (default: 0)
  --light.egress value                Outgoing bandwidth limit for serving light clients (kil
obytes/sec, 0 = unlimited) (default: 0)
  --light.maxpeers value              Maximum number of light clients to serve, or light serv
ers to attach to (default: 100)
  --ulc.servers value                 List of trusted ultra-light servers
  --ulc.fraction value                Minimum % of trusted ultra-light servers required to an
nounce a new head (default: 75)
  --ulc.onlyannounce                  Ultra light server sends announcements only
  --light.nopruning                   Disable ancient light chain data pruning
  --light.nosyncserve                 Enables serving light clients before syncing
  
DEVELOPER CHAIN OPTIONS:
  --dev                               Ephemeral proof-of-authority network with a pre-funded 
developer account, mining enabled
  --dev.period value                  Block period to use in developer mode (0 = mine only if
 transaction pending) (default: 0)
  --dev.gaslimit value                Initial block gas limit (default: 11500000)
  
ETHASH OPTIONS:
  --ethash.cachedir value             Directory to store the ethash verification caches (defa
ult = inside the datadir)
  --ethash.cachesinmem value          Number of recent ethash caches to keep in memory (16MB 
each) (default: 2)
  --ethash.cachesondisk value         Number of recent ethash caches to keep on disk (16MB ea
ch) (default: 3)
  --ethash.cacheslockmmap             Lock memory maps of recent ethash caches
  --ethash.dagdir value               Directory to store the ethash mining DAGs (default: "/h
ome/info/.ethash")
  --ethash.dagsinmem value            Number of recent ethash mining DAGs to keep in memory (
1+GB each) (default: 1)
  --ethash.dagsondisk value           Number of recent ethash mining DAGs to keep on disk (1+
GB each) (default: 2)
  --ethash.dagslockmmap               Lock memory maps for recent ethash mining DAGs
  
TRANSACTION POOL OPTIONS:
  --txpool.locals value               Comma separated accounts to treat as locals (no flush, 
priority inclusion)
  --txpool.nolocals                   Disables price exemptions for locally submitted transac
tions
  --txpool.journal value              Disk journal for local transaction to survive node rest
arts (default: "transactions.rlp")
  --txpool.rejournal value            Time interval to regenerate the local transaction journ
al (default: 1h0m0s)
  --txpool.pricelimit value           Minimum gas price limit to enforce for acceptance into 
the pool (default: 1)
  --txpool.pricebump value            Price bump percentage to replace an already existing tr
ansaction (default: 10)
  --txpool.accountslots value         Minimum number of executable transaction slots guarante
ed per account (default: 16)
  --txpool.globalslots value          Maximum number of executable transaction slots for all 
accounts (default: 5120)
  --txpool.accountqueue value         Maximum number of non-executable transaction slots perm
itted per account (default: 64)
  --txpool.globalqueue value          Maximum number of non-executable transaction slots for 
all accounts (default: 1024)
  --txpool.lifetime value             Maximum amount of time non-executable transaction are q
ueued (default: 3h0m0s)
  
PERFORMANCE TUNING OPTIONS:
  --cache value                       Megabytes of memory allocated to internal caching (defa
ult = 4096 mainnet full node, 128 light mode) (default: 1024)
  --cache.database value              Percentage of cache memory allowance to use for databas
e io (default: 50)
  --cache.trie value                  Percentage of cache memory allowance to use for trie ca
ching (default = 15% full mode, 30% archive mode) (default: 15)
  --cache.trie.journal value          Disk journal directory for trie cache to survive node r
estarts (default: "triecache")
  --cache.trie.rejournal value        Time interval to regenerate the trie cache journal (def
ault: 1h0m0s)
  --cache.gc value                    Percentage of cache memory allowance to use for trie pr
uning (default = 25% full mode, 0% archive mode) (default: 25)
  --cache.snapshot value              Percentage of cache memory allowance to use for snapsho
t caching (default = 10% full mode, 20% archive mode) (default: 10)
  --cache.noprefetch                  Disable heuristic state prefetch during block import (l
ess CPU and disk IO, more time waiting for data)
  --cache.preimages                   Enable recording the SHA3/keccak preimages of trie keys
  --fdlimit value                     Raise the open file descriptor resource limit (default 
= system fd limit) (default: 0)
  
ACCOUNT OPTIONS:
  --unlock value                      Comma separated list of accounts to unlock
  --password value                    Password file to use for non-interactive password input
  --signer value                      External signer (url or path to ipc file)
  --allow-insecure-unlock             Allow insecure account unlocking when account-related R
PCs are exposed by http
  
API AND CONSOLE OPTIONS:
  --ipcdisable                        Disable the IPC-RPC server
  --ipcpath value                     Filename for IPC socket/pipe within the datadir (explic
it paths escape it)
  --http                              Enable the HTTP-RPC server
  --http.addr value                   HTTP-RPC server listening interface (default: "localhos
t")
  --http.port value                   HTTP-RPC server listening port (default: 8545)
  --http.api value                    API's offered over the HTTP-RPC interface
  --http.rpcprefix value              HTTP path path prefix on which JSON-RPC is served. Use 
'/' to serve on all paths.
  --http.corsdomain value             Comma separated list of domains from which to accept cr
oss origin requests (browser enforced)
  --http.vhosts value                 Comma separated list of virtual hostnames from which to
 accept requests (server enforced). Accepts '*' wildcard. (default: "localhost")
  --ws                                Enable the WS-RPC server
  --ws.addr value                     WS-RPC server listening interface (default: "localhost"
)
  --ws.port value                     WS-RPC server listening port (default: 8546)
  --ws.api value                      API's offered over the WS-RPC interface
  --ws.rpcprefix value                HTTP path prefix on which JSON-RPC is served. Use '/' t
o serve on all paths.
  --ws.origins value                  Origins from which to accept websockets requests
  --authrpc.jwtsecret value           Path to a JWT secret to use for authenticated RPC endpo
ints
  --authrpc.addr value                Listening address for authenticated APIs (default: "loc
alhost")
  --authrpc.port value                Listening port for authenticated APIs (default: 8551)
  --authrpc.vhosts value              Comma separated list of virtual hostnames from which to
 accept requests (server enforced). Accepts '*' wildcard. (default: "localhost")
  --graphql                           Enable GraphQL on the HTTP-RPC server. Note that GraphQ
L can only be started if an HTTP server is started as well.
  --graphql.corsdomain value          Comma separated list of domains from which to accept cr
oss origin requests (browser enforced)
  --graphql.vhosts value              Comma separated list of virtual hostnames from which to
 accept requests (server enforced). Accepts '*' wildcard. (default: "localhost")
  --rpc.gascap value                  Sets a cap on gas that can be used in eth_call/estimate
Gas (0=infinite) (default: 50000000)
  --rpc.evmtimeout value              Sets a timeout used for eth_call (0=infinite) (default:
 5s)
  --rpc.txfeecap value                Sets a cap on transaction fee (in ether) that can be se
nt via the RPC APIs (0 = no cap) (default: 1)
  --rpc.allow-unprotected-txs         Allow for unprotected (non EIP155 signed) transactions 
to be submitted via RPC
  --jspath loadScript                 JavaScript root path for loadScript (default: ".")
  --exec value                        Execute JavaScript statement
  --preload value                     Comma separated list of JavaScript files to preload int
o the console
  
NETWORKING OPTIONS:
  --bootnodes value                   Comma separated enode URLs for P2P discovery bootstrap
  --discovery.dns value               Sets DNS discovery entry points (use "" to disable DNS)
  --port value                        Network listening port (default: 30303)
  --maxpeers value                    Maximum number of network peers (network disabled if se
t to 0) (default: 50)
  --maxpendpeers value                Maximum number of pending connection attempts (defaults
 used if set to 0) (default: 0)
  --nat value                         NAT port mapping mechanism (any|none|upnp|pmp|extip:<IP
>) (default: "any")
  --nodiscover                        Disables the peer discovery mechanism (manual peer addi
tion)
  --v5disc                            Enables the experimental RLPx V5 (Topic Discovery) mech
anism
  --netrestrict value                 Restricts network communication to the given IP network
s (CIDR masks)
  --nodekey value                     P2P node key file
  --nodekeyhex value                  P2P node key as hex (for testing)
  
MINER OPTIONS:
  --mine                              Enable mining
  --miner.threads value               Number of CPU threads to use for mining (default: 0)
  --miner.notify value                Comma separated HTTP URL list to notify of new work pac
kages
  --miner.notify.full                 Notify with pending block headers instead of work packa
ges
  --miner.gasprice value              Minimum gas price for mining a transaction (default: 10
00000000)
  --miner.gaslimit value              Target gas ceiling for mined blocks (default: 8000000)
  --miner.etherbase value             Public address for block mining rewards (default = firs
t account) (default: "0")
  --miner.extradata value             Block extra data set by the miner (default = client ver
sion)
  --miner.recommit value              Time interval to recreate the block being mined (defaul
t: 3s)
  --miner.noverify                    Disable remote sealing verification
  
GAS PRICE ORACLE OPTIONS:
  --gpo.blocks value                  Number of recent blocks to check for gas prices (defaul
t: 20)
  --gpo.percentile value              Suggested gas price is the given percentile of a set of
 recent transaction gas prices (default: 60)
  --gpo.maxprice value                Maximum transaction priority fee (or gasprice before Lo
ndon fork) to be recommended by gpo (default: 500000000000)
  --gpo.ignoreprice value             Gas price below which gpo will ignore transactions (def
ault: 2)
  
VIRTUAL MACHINE OPTIONS:
  --vmdebug                           Record information useful for VM and contract debugging
  
LOGGING AND DEBUGGING OPTIONS:
  --fakepow                           Disables proof-of-work verification
  --nocompaction                      Disables db compaction after import
  --verbosity value                   Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4
=debug, 5=detail (default: 3)
  --vmodule value                     Per-module verbosity: comma-separated list of <pattern>
=<level> (e.g. eth/*=5,p2p=4)
  --log.json                          Format logs with JSON
  --log.backtrace value               Request a stack trace at a specific logging statement (
e.g. "block.go:271")
  --log.debug                         Prepends log messages with call-site location (file and
 line number)
  --pprof                             Enable the pprof HTTP server
  --pprof.addr value                  pprof HTTP server listening interface (default: "127.0.
0.1")
  --pprof.port value                  pprof HTTP server listening port (default: 6060)
  --pprof.memprofilerate value        Turn on memory profiling with the given rate (default: 
524288)
  --pprof.blockprofilerate value      Turn on block profiling with the given rate (default: 0
)
  --pprof.cpuprofile value            Write CPU profile to the given file
  --trace value                       Write execution trace to the given file
  
METRICS AND STATS OPTIONS:
  --metrics                              Enable metrics collection and reporting
  --metrics.expensive                    Enable expensive metrics collection and reporting
  --metrics.addr value                   Enable stand-alone metrics HTTP server listening int
erface (default: "127.0.0.1")
  --metrics.port value                   Metrics HTTP server listening port (default: 6060)
  --metrics.influxdb                     Enable metrics export/push to an external InfluxDB d
atabase
  --metrics.influxdb.endpoint value      InfluxDB API endpoint to report metrics to (default:
 "http://localhost:8086")
  --metrics.influxdb.database value      InfluxDB database name to push reported metrics to (
default: "geth")
  --metrics.influxdb.username value      Username to authorize access to the database (defaul
t: "test")
  --metrics.influxdb.password value      Password to authorize access to the database (defaul
t: "test")
  --metrics.influxdb.tags value          Comma-separated InfluxDB tags (key/values) attached 
to all measurements (default: "host=localhost")
  --metrics.influxdbv2                   Enable metrics export/push to an external InfluxDB v
2 database
  --metrics.influxdb.token value         Token to authorize access to the database (v2 only) 
(default: "test")
  --metrics.influxdb.bucket value        InfluxDB bucket name to push reported metrics to (v2
 only) (default: "geth")
  --metrics.influxdb.organization value  InfluxDB organization name (v2 only) (default: "geth
")
  
ALIASED (deprecated) OPTIONS:
  --nousb                             Disables monitoring for and managing USB hardware walle
ts (deprecated)
  --whitelist value                   Comma separated block number-to-hash mappings to enforc
e (<number>=<hash>) (deprecated in favor of --peer.requiredblocks)
  
MISC OPTIONS:
  --snapshot                                Enables snapshot-database mode (default = enable)
  --bloomfilter.size value                  Megabytes of memory allocated to bloom-filter for
 pruning (default: 2048)
  --help, -h                                show help
  --override.arrowglacier value             Manually specify Arrow Glacier fork-block, overri
ding the bundled setting (default: 0)
  --override.terminaltotaldifficulty value  Manually specify TerminalTotalDifficulty, overrid
ing the bundled setting (default: 0)
  
COPYRIGHT:
   Copyright 2013-2022 The go-ethereum Authors
```
### 次はSolidityコンパイラ（solc）のインストール
add-apt-repositoryとapt updateは上でやってるのでいきなりいきます。
```shell
sudo apt install solc
```
バージョンを確認する
```shell
solc --version

solc, the solidity compiler commandline interface
Version: 0.8.13+commit.abaa5c0e.Linux.g++
```
OK
どこに入ったかな？
```shell
info@web3:~/solidity$ which geth
/usr/bin/geth
info@web3:~/solidity$ which solc
/usr/bin/solc
```
/usr/bin/の下に入ったようです。

### Rimix（Browser-Solidity）
先人様のページには二つの方法が書いてあって、
1. GitHubのリポジトリをクローンし、ローカルで立ち上げる
2. クラウドIDE
今回はクラウドIDEで行こうと思うのですが、先人様のページにあるクラウドIDEのリンクは既に移動してこんなメッセージが出るので新しい方へ行ってみます。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/7103/7e075c79-29bc-5921-c96e-e4a4147b6798.png)

ここです。

RemixIDE
http://remix.ethereum.org

こんなページが開きました。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/7103/63bc9cc4-1364-e701-8dc6-20b7dc5049c9.png)
Google翻訳先生にお願いするとこうなりました。
少しゆっくり眺めてみようと思います。

今日はここまで。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/7103/aa44c77b-2257-8a9d-14c2-28810e5472d5.png)

と思ったけど、せっかくGethを入れたので
@kagami-r0927 さんのところにあるこれをやってみた。

>Ethereum [プライベートネットワークに接続する] 
https://qiita.com/kagami-r0927/items/af31aa6d51053787de43 #Qiita 

普通に動いたようなので、次は、これをやってみました。よくできたチュートリアルです。

>イーサリアム上のDApp開発をゲームを作って学びましょう
CryptoZombiesは、暗号からゾンビを生み出すゲームの開発を通じて、Solidityでスマートコントラクトの構築を学習できる、インタラクティブなオンラインレッスンです。
https://cryptozombies.io/jp/