// HelloWorld.sol
pragma solidity ^0.8.17;
contract HelloWorld {
string public greet = "Hello World!";
}
<script src="https://.../web3.min.js"></script>
<input
type="button"
value="Connect Wallet"
onclick="connect();"
>
async function connect() {
if (!window.ethereum) return;
await window.ethereum.request({ method: "eth_requestAccounts" });
window.web3 = new Web3(window.ethereum);
console.log(`Wallet: ${web3.eth.currentProvider.selectedAddress}`);
}
Web3.utils.sha3("example")
// '0x6fd43e7cffc31bb581d7421c8698e29aa2bd8e7186a394b85299908b4eb9b175'
Web3.utils.toWei('1', 'ether') // 1000000000000000000
Web3.utils.toWei('1', 'gwei') // 1000000000
Web3.utils.padLeft('0x3456ff', 20); // '0x000000000000003456ff'
import Web3 from 'web3'
const web3 = new Web3("https://mainnet.infura.io/v3/<API-KEY>")
web3.eth.getBalance("0x1b3cB81E51011...").then(console.log)
// result: BigInt(560000000065000000000000)
web3.eth.getBlockNumber().then(console.log)
// result: BigInt(13497160)
import Web3 from 'web3'
const web3 = new Web3(Web3.givenProvider || "ws://localhost:8545");
const abi = [...];
const address = "0xe435e2a3cb5dc62c75d8bb2dba8470771405911d";
const contract = new web3.eth.Contract(abi, address);
contract.methods.getValue().call().then(console.log);
...
const abi = [...];
const address = "0xe435e2a3cb5dc62c75d8bb2dba8470771405911d";
const contract = new web3.eth.Contract(abi, address);
const subscription = await contract.events.VALUE_CHANGE();
subscription.on("data", console.log);
npm install
wagmi
viem
@web3modal/ethereum
@web3modal/react
return (
<>
<WagmiConfig config={wagmiConfig}>
<HomePage />
</WagmiConfig>
<Web3Modal projectId={projectId} ethereumClient={ethereumClient} />
</>
)
import { Web3Button } from '@web3modal/react'
function HomePage() {
return <Web3Button />
}
$ mkdir my-smart-contract
$ cd my-smart-contract
$ npm init
$ npm install --save-dev hardhat
$ npx hardhat
? What do you want to do? …
❯ Create a JavaScript project
Create a TypeScript project
Create an empty hardhat.config.js
Quit
$ npx hardhat node
Started HTTP and WebSocket JSON-RPC server at http://127.0.0.1:8545/
Accounts
========
Account #0: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 (10000 ETH)
Private Key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efca...
$ npx hardhat run --network %your-network% scripts/deploy.js
$ npm install -g @fleekhq/fleek-cli
$ fleek site:init
$ fleek site:deploy
Оцените доклад