To provide blockchain integrity between dev team members, uninterrupted blockchain server is needed. and public test network such as goerli is too slow. Heres how to deploy your own ganache network on cloud vm
start a vm. aws freetier t2 micro is ok
go to network setting allow port 8545 inbound traffic
ssh into vm
sudo apt install curl
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.profile
nvm install 16
npm install -g ganache-cli
ganache-cli --host 0.0.0.0 --port 8545 --networkId 5777
use below code to test connection
ref : https://dev.to/zenika/build-your-own-remote-private-blockchain-with-aws-and-ganache-4330
const Web3 = require('web3');
const web3 = new Web3(`http://<VM_PUBLIC_IP>:8545`); // http provider
// const web3 = new Web3(`ws://<VM_PUBLIC_IP>:8545`); // websocket provider
const main = async () => {
const accounts = await web3.eth.getAccounts();
const accountOneBalance = await web3.eth
.getBalance(accounts[0])
.then((b) => web3.utils.fromWei(b, 'ether'));
console.log('accountOneBalance', accountOneBalance);
};
main();
ref : https://www.joinc.co.kr/w/Site/Linux/Locale
sudo locale-gen ko_KR.UTF-8
cat /etc/default/locale
LANG="ko_KR.UTF-8"
TZ='Asia/Seoul' date "+%Y-%m-%d:%T"
use init.sh
to make ganache runs on background even when terminal disconnected.
since it's running on background you need to use teardown.sh
to stop ganache
logfile will be created upon every execution of init.sh
ref : https://unix.stackexchange.com/questions/420594/why-process-killed-with-nohup
init.sh
#!/bin/bash
touch ganache_$(TZ="Asia/Seoul" date "+%Y-%m-%d:%T").log
ganache-cli --host 0.0.0.0 --port 8545 --networkId 5777 --verbose > ganache_$(TZ="Asia/Seoul" date "+%Y-%m-%d:%T").log & disown
tail -f ganache_$(TZ="Asia/Seoul" date "+%Y-%m-%d:%T").log
teardown.sh
#!/bin/bash
kill $(pgrep node)