From e74971499c556759757ff1d96328082092644515 Mon Sep 17 00:00:00 2001 From: Julien Klepatch Date: Fri, 22 Oct 2021 17:43:35 +0800 Subject: [PATCH] web3 in 2 mins --- screencast/420-web3-in-2-mins/MyContract.sol | 13 +++++++++++++ screencast/420-web3-in-2-mins/script.js | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 screencast/420-web3-in-2-mins/MyContract.sol create mode 100644 screencast/420-web3-in-2-mins/script.js diff --git a/screencast/420-web3-in-2-mins/MyContract.sol b/screencast/420-web3-in-2-mins/MyContract.sol new file mode 100644 index 0000000000..f7e69c458b --- /dev/null +++ b/screencast/420-web3-in-2-mins/MyContract.sol @@ -0,0 +1,13 @@ +pragma solidity 0.8.0; + +contract MyContractol { + uint data; + + function read() external view returns(uint) { + return data; + } + + function write(uint _data) external { + data = _data; + } +} \ No newline at end of file diff --git a/screencast/420-web3-in-2-mins/script.js b/screencast/420-web3-in-2-mins/script.js new file mode 100644 index 0000000000..c8a326dc86 --- /dev/null +++ b/screencast/420-web3-in-2-mins/script.js @@ -0,0 +1,17 @@ +const Web3 = require('web3'); + +const web3 = new Web3('https://mainnet.infura.io/v3/ed18016b210c4a1baf828458bd16feb0'); + +web3.eth.accounts.wallet.add('0x55d0380decced82a2198582e541a129e8b86937c30a1c51bbb5327b9f00c6aa4'); + +web3.eth.getBalance('0xFA17F09e8464Bd0c592Daf09bf285B5cD72Bec3D') +.then(balance => console.log(balance)); + +const contract = new web3.eth.Contract(abi, '0x6E62c6e07019Bc3db5554a8d602390C6CC0B7846'); + +contract.methods.read().call() +.then(result => console.log(result)); + +web3.eth.sendTransaction({from: '0xFA17F09e8464Bd0c592Daf09bf285B5cD72Bec3D', value: 1000}) + +contract.methods.write().sendTransaction({from: '0xFA17F09e8464Bd0c592Daf09bf285B5cD72Bec3D'});