Web3 commands チートシート(初心者向け)
はじめに
初心者の方、そして私向けに作成しました。
学習初めは何度も検索するので、まとめました。
主観でまとめただけなので、詳しくはドキュメントをみてください
Web3
web3 commands
確認用
私はこれでなんとなく動きを理解しました。
web3.eth.getBlockNumber()
//1eth
web3.eth.sendTransaction({from: accounts[1] , to: accounts[2] , value:"1000000000000000000"})
response
{
transactionHash: 'ADDRESS',
transactionIndex: 0,
blockHash: 'ADDRESS',
blockNumber: 12,
from: 'ADDRESS',
to: 'ADDRESS',
gasUsed: 21000,
cumulativeGasUsed: 21000,
contractAddress: null,
logs: [],
status: true,
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
}
web3.eth.getBalance(accounts[1])
web3.eth.getBalance(accounts[2])
web3.currentProvider
現在のフロバイダー情報
response
HttpProvider {
withCredentials: false,
timeout: 0,
headers: undefined,
agent: undefined,
connected: true,
host: 'http://127.0.0.1:7545',
httpAgent: Agent {
_events: [Object: null prototype] {
free: [Function (anonymous)],
newListener: [Function: maybeEnableKeylog]
},
_eventsCount: 2,
_maxListeners: undefined,
defaultPort: 80,
protocol: 'http:',
options: [Object: null prototype] { keepAlive: false, path: null },
requests: [Object: null prototype] {},
sockets: [Object: null prototype] {},
freeSockets: [Object: null prototype] {},
keepAliveMsecs: 1000,
keepAlive: false,
maxSockets: Infinity,
maxFreeSockets: 256,
scheduling: 'lifo',
maxTotalSockets: Infinity,
totalSocketCount: 0,
[Symbol(kCapture)]: false
},
send: [Function (anonymous)],
_alreadyWrapped: true
}
デフォルトのアカウント確認・セット
web3.eth.defaultAccount;
> undefined
web3.eth.defaultAccount = 'address';
web3.eth.defaultAccount = 'address';
'address'
web3.eth.defaultAccount;
'address'
getProtocolVersion
web3.eth.getProtocolVersion()
出現率高そう
getTransaction
指定されたトランザクションハッシュに一致するトランザクションを返します。
このあたりはよく使いそう
web3.eth.getTransaction('transactionHash').then(console.log);
web3.eth.getTransactionReceipt('transactionHash').then(console.log);
signTransaction
web3.eth.accounts.signTransactionを使用して生成された、すでに署名されたトランザクションを送信します。
web3.eth.sendSignedTransaction(signedTransactionData [, callback])
EstimateGas
メッセージ呼び出しまたはトランザクションを実行し、使用されたガスの量を返します。
```
web3.eth.estimateGas(callObject [, callback])
getProof
マークルプルーフを含む、指定されたアカウントのアカウントとストレージ値を返します。
web3.eth.estimateGas(callObject [, callback])
### 実装では必要そう
BatchRequest
バッチリクエストを作成して実行するクラス。
var contract = new web3.eth.Contract(abi, address);
var batch = new web3.BatchRequest();
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000000', 'latest', callback));
batch.add(contract.methods.balance(address).call.request({from: '0x0000000000000000000000000000000000000000'}, callback2));
batch.execute();
```
handleRevert
多分トランザクション中のエラー処理で使用しそう
web3.eth.handlRevert;
> false
// turn revert handling on
web3.eth.handleRevert = true;
getStorageAt
web3.eth.getStorageAt("CONTRACT_ADDRESS", 0)
おまけ
多分更新していきます。
Author And Source
この問題について(Web3 commands チートシート(初心者向け)), 我々は、より多くの情報をここで見つけました https://qiita.com/MDevelopper/items/3ad1dda17d6c15c351fc著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .