[Ethereum] シンプルなスマートコントラクトをデプロイ

$ mkdir rinkeby
$ cd rinkeby
$ npm init

{
  "name": "inbox",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

solidityのcompilerをinstall
$ npm install –save solc

mocha(テストフレーム)をinstall
$ npm install –save mocha ganache-cli web3@1.0.0-beta.26

truffle-hdwallet-providerをインストール
$ npm install –save truffle-hdwallet-provider@0.0.3

const path = require('path');
const fs = require('fs');
const solc = require('solc');

const inboxPath = path.resolve(__dirname, 'contracts', 'Inbox.sol');
const source = fs.readFileSync(inboxPath, 'utf8');

moudle.exports = solc.compile(source,1).contracts[':Inbox'];

Inbox.sol

pragma solidity ^0.8.11;

contract Inbox {
	string public message;

	function Inbox(string initialMessage) public {
		message = initialMessage;
	}

	function setMessage(string newMessage) public {
		message = newMessage;
	}
}

deploy.js

const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const { interface, bytecode } = require('./compile');

const provider = new HDWalletProvider (
	'harmonic',
	'https://ropsten.infura.io/v3/*'
);

const web3 = new Web3(provider);

const deploy = async () => {

	const accounts = await web3.eth.getAccounts();

	console.log('Attempting to deploy from account', accounts[0]);

	const result = await new web3.eth.Contract(JSON.parse(interface))
		.deploy({data: bytecode, arguments:['Hi there!']})
		.send({gas:'1000000', from: accounts:[0]});

	console.log('Contract deploy to', result.options.address);
}

$ node deploy.js
Attempting to deploy from account *
(node:408216) UnhandledPromiseRejectionWarning: Error: intrinsic gas too low

うーむ、gasの設定の方法がよくわかん
gasの概念の理解が先か…