LoginSignup
0
0

Web3 Ethパッケージ利用についてのまとめ

Posted at

こちらはWeb3 4.7.0のパッケージを利用されている
「現時点2024/4/5最新版」でございます

  "dependencies": {
    "web3": "^4.7.0"
  }

アカウント情報を取得

web3.eth.getAccounts().then(function(obj) {
    console.log(obj)
});

残高情報を取得

web3.eth.getBalance('0xb10549760b07416e4cbd1ab31da9d24165ef3ae6').then(function(value){
    console.log(web3.utils.fromWei(value, 'ether'))
})

アカウントを新規作成

let newAccount = web3.eth.accounts.create()
console.log(newAccount);

大量アカウントを作成して、残高情報を取得

アカウントアドレスの生成はタイムスタンプを入れているようなので、運でお金持ちになるなんて、ありえないです。

for (let i=0; i<100; i++) {
    let newAccount = web3.eth.accounts.create()
    console.log(newAccount.address);

    web3.eth.getBalance(newAccount.address).then(function(value){
        if (web3.utils.fromWei(value, 'ether') > 0) {
            console.log(newAccount)
        }
    })
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0