Skip to content

Commit

Permalink
changed all double-quotes to single-quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
web3js-org committed Jan 4, 2024
1 parent 3a85fa5 commit cb6c434
Show file tree
Hide file tree
Showing 21 changed files with 424 additions and 424 deletions.
16 changes: 8 additions & 8 deletions docs/docs/guides/events_subscriptions/custom_subscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ You need to specify the exact data that will be passed to the provider. You do t
```ts
protected _buildSubscriptionParams() {
// the `someCustomSubscription` below is the name of the subscription provided by the node you are connected to.
return ["someCustomSubscription", this.args];
return ['someCustomSubscription', this.args];
}
```

With the implementation above, the call that will be made to the provider will be as follow:

```ts
{
id: "[GUID-STRING]", // something like: '3f839900-afdd-4553-bca7-b4e2b835c687'
id: '[GUID-STRING]', // something like: '3f839900-afdd-4553-bca7-b4e2b835c687'
jsonrpc: '2.0',
method: 'eth_subscribe',
// The `someCustomSubscription` below is the name of the subscription provided by the node you are connected to.
Expand Down Expand Up @@ -130,11 +130,11 @@ const web3 = new Web3({
// subscribe at the provider:
// Note: this will internally initialize a new instance of `MyCustomSubscription`,
// call `_buildSubscriptionParams`, and then send the `eth_subscribe` RPC call.
const sub = web3.subscriptionManager.subscribe("custom", args);
const sub = web3.subscriptionManager.subscribe('custom', args);

// listen to the emitted event:
// Note: the data will be optionally formatted at `formatSubscriptionResult`, before it is emitted here.
sub.on("data", (result) => {
sub.on('data', (result) => {
// This will be called every time a new data arrived from the provider to this subscription
});
```
Expand Down Expand Up @@ -164,7 +164,7 @@ class MyCustomSubscription extends Web3Subscription<
> {
protected _buildSubscriptionParams() {
// the `someCustomSubscription` below is the name of the subscription provided by the node your are connected to.
return ["someCustomSubscription", this.args];
return ['someCustomSubscription', this.args];
}

protected formatSubscriptionResult(data: string) {
Expand All @@ -187,7 +187,7 @@ class MyCustomSubscription extends Web3Subscription<
// Usage

const args = {
customArg: "hello custom",
customArg: 'hello custom',
};

const CustomSubscriptions = {
Expand All @@ -204,9 +204,9 @@ const web3 = new Web3({
registeredSubscriptions: CustomSubscriptions,
});

const sub = web3.subscriptionManager.subscribe("custom", args);
const sub = web3.subscriptionManager.subscribe('custom', args);

sub.on("data", (result) => {
sub.on('data', (result) => {
// New data
});

Expand Down
48 changes: 24 additions & 24 deletions docs/docs/guides/getting_started/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ After instantiating the `web3` instance with a `new Web3 provider`, we can acces

```ts
// get the balance of an address
await web3.eth.getBalance("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
await web3.eth.getBalance('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045');
// ↳ 114438180989009447638n

// get last block number
Expand All @@ -74,7 +74,7 @@ await web3.eth.getChainId();
// ↳ 1n

// get the nonce of an address
await web3.eth.getTransactionCount("0x37826D8B5F4B175517A0f42c886f8Fca38C55Fe7");
await web3.eth.getTransactionCount('0x37826D8B5F4B175517A0f42c886f8Fca38C55Fe7');
// ↳ 7n

// get the current gas price
Expand Down Expand Up @@ -118,7 +118,7 @@ Wallet(1)

```ts
//the private key must start with the '0x' prefix
const account = web3.eth.accounts.wallet.add("0x50d349f5cf627d44858d6fcb6fbf15d27457d35c58ba2d5cfeaf455f25db5bec");
const account = web3.eth.accounts.wallet.add('0x50d349f5cf627d44858d6fcb6fbf15d27457d35c58ba2d5cfeaf455f25db5bec');

console.log(account[0].address);
//↳ 0xcE6A5235d6033341972782a15289277E85E5b305
Expand All @@ -131,21 +131,21 @@ console.log(account[0].privateKey);

```ts title='Sending value'
//add an account to a wallet
const account = web3.eth.accounts.wallet.add("0x50d349f5cf627d44858d6fcb6fbf15d27457d35c58ba2d5cfeaf455f25db5bec");
const account = web3.eth.accounts.wallet.add('0x50d349f5cf627d44858d6fcb6fbf15d27457d35c58ba2d5cfeaf455f25db5bec');

//create transaction object to send 1 eth to '0xa32...c94' address from the account[0]
const tx =
{
from: account[0].address,
to: "0xa3286628134bad128faeef82f44e99aa64085c94",
value: web3.utils.toWei("1", "ether")
to: '0xa3286628134bad128faeef82f44e99aa64085c94',
value: web3.utils.toWei('1', 'ether')
};
//the `from` address must match the one previously added with wallet.add

//send the transaction
const txReceipt = await web3.eth.sendTransaction(tx);

console.log("Tx hash:", txReceipt.transactionHash)
console.log('Tx hash:', txReceipt.transactionHash)
// ↳ Tx hash: 0x03c844b069646e08af1b6f31519a36e3e08452b198ef9f6ce0f0ccafd5e3ae0e
```

Expand All @@ -157,20 +157,20 @@ The first step to interact with a contract is to instantiate the contract, for w

```ts
//Uniswap token address in mainnet
const address = "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984"
const address = '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984'

//you can find the complete ABI in etherscan.io
const ABI =
[
{
name: "symbol",
outputs: [{ type: "string" }],
type: "function",
name: 'symbol',
outputs: [{ type: 'string' }],
type: 'function',
},
{
name: "totalSupply",
outputs: [{ type: "uint256" }],
type: "function",
name: 'totalSupply',
outputs: [{ type: 'uint256' }],
type: 'function',
},
];

Expand All @@ -184,41 +184,41 @@ const uniswapToken = new web3.eth.Contract(abi, address);
//make the call to the contract
const symbol = await uniswapToken.methods.symbol().call();

console.log("Uniswap symbol:",symbol);
console.log('Uniswap symbol:',symbol);
// ↳ Uniswap symbol: UNI

//make the call to the contract
const totalSupply = await uniswapToken.methods.totalSupply().call();

console.log("Uniswap Total supply:", totalSupply);
console.log('Uniswap Total supply:', totalSupply);
// ↳ Uniswap Total Supply: 1000000000000000000000000000n

//use web3 utils to format the units
console.log(web3.utils.fromWei(totalSupply, "ether"))
console.log(web3.utils.fromWei(totalSupply, 'ether'))
// ↳ 1000000000
```

### Writing-methods

```ts
//address to send the token
const to = "0xcf185f2F3Fe19D82bFdcee59E3330FD7ba5f27ce";
const to = '0xcf185f2F3Fe19D82bFdcee59E3330FD7ba5f27ce';

//value to transfer (1 with 18 decimals)
const value = web3.utils.toWei("1","ether");
const value = web3.utils.toWei('1','ether');

//send the transaction => return the Tx receipt
const txReceipt = await uniswapToken.methods.transfer(to,value).send({from: account[0].address});

console.log("Tx hash:",txReceipt.transactionHash);
console.log('Tx hash:',txReceipt.transactionHash);
// ↳ Tx hash: 0x14273c2b5781cc8f1687906c68bfc93482c603026d01b4fd37a04adb6217ad43
```

### Query past events

```ts
//get past `Transfer` events from block 18850576
const eventTransfer = await uniswapToken.getPastEvents("Transfer", { fromBlock: 18850576 });
const eventTransfer = await uniswapToken.getPastEvents('Transfer', { fromBlock: 18850576 });

console.log(eventTransfer);
// ↳ [{...},{...}, ...] array with all the events emitted
Expand All @@ -235,15 +235,15 @@ You MUST initialize the `Web3 provider` with a WebSocket endpoint to subscribe t
import { Web3 } from 'web3';

//WebSocket provider
const web3 = new Web3("wss://ethereum.publicnode.com");
const web3 = new Web3('wss://ethereum.publicnode.com');

//instantiate contract
const uniswapToken = new web3.eth.Contract(abi, address)

//create the subcription to all the "Transfer" events
//create the subcription to all the 'Transfer' events
const subscription = uniswapToken.events.Transfer();

//listen to the events
subscription.on("data",console.log);
subscription.on('data',console.log);
// ↳ [{...},{...}, ...] live events will be printed in the console
```
44 changes: 22 additions & 22 deletions docs/docs/guides/getting_started/metamask.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ sidebar_label: Connecting to Metamask
After creating your react app `npx create-react-app app-name`, and installing web3 `npm i web3` you can go to `src/app.js`, you can clean up the code and import `{Web3}`. It should look like this:

```jsx
import { useState } from "react";
import { Web3 } from "web3";
import { useState } from 'react';
import { Web3 } from 'web3';

function App() {
return <> </>;
Expand All @@ -26,13 +26,13 @@ Let's divide this into 2 small steps:
In this step, we'll add a button to the front end for users to connect to Metamask. We'll also include an `<h2></h2>` element to display the connected address once the connection is established.

```jsx
import { useState } from "react";
import { Web3 } from "web3";
import { useState } from 'react';
import { Web3 } from 'web3';

function App() {
//highlight-start
//react state to store and show the connected account
const [connectedAccount, setConnectedAccount] = useState("null");
const [connectedAccount, setConnectedAccount] = useState('null');
//highlight-end

return (
Expand All @@ -55,12 +55,12 @@ export default App;
In this step, we'll implement the function that triggers Metamask to prompt the user to connect their wallet.

```jsx {}
import { useState } from "react";
import { Web3 } from "web3";
import { useState } from 'react';
import { Web3 } from 'web3';

function App() {
//state to store and show the connected account
const [connectedAccount, setConnectedAccount] = useState("null");
const [connectedAccount, setConnectedAccount] = useState('null');

//highlight-start
async function connectMetamask() {
Expand All @@ -70,15 +70,15 @@ function App() {
const web3 = new Web3(window.ethereum);

//request user to connect accounts (Metamask will prompt)
await window.ethereum.request({ method: "eth_requestAccounts" });
await window.ethereum.request({ method: 'eth_requestAccounts' });

//get the connected accounts
const accounts = await web3.eth.getAccounts();

//show the first connected account in the react page
setConnectedAccount(accounts[0]);
} else {
alert("Please download metamask");
alert('Please download metamask');
}
}
//highlight-end
Expand Down Expand Up @@ -108,7 +108,7 @@ export default App;
//highlight-start
<title>Metamask Connection</title>
<!-- Import Web3 library from CDN -->
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js'></script>
//highlight-end
</head>
<body>
Expand All @@ -124,17 +124,17 @@ export default App;
<head>
<title>Metamask Connection</title>
<!-- Import Web3 library from CDN -->
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js'></script>
</head>
<body>
//highlight-start
<h1>Metamask Connection</h1>

<!-- button to connect Metamask -->
<button id="connectButton">Connect to Metamask</button>
<button id='connectButton'>Connect to Metamask</button>

<!-- display the connected account -->
<h2 id="connectedAccount">null</h2>
<h2 id='connectedAccount'>null</h2>
//highlight-end
</body>
</html>
Expand All @@ -148,35 +148,35 @@ export default App;
<head>
<title>Metamask Connection</title>
<!-- Import Web3 library from CDN -->
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js'></script>
</head>
<body>
<h1>Metamask Connection</h1>

<!-- button to connect Metamask -->
<button id="connectButton">Connect to Metamask</button>
<button id='connectButton'>Connect to Metamask</button>

<!-- display the connected account -->
<h2 id="connectedAccount">null</h2>
<h2 id='connectedAccount'>null</h2>

//highlight-start
<script type="module">
<script type='module'>
//listen for a `click` to connect when clicking the button
document.getElementById("connectButton").addEventListener("click", async () => {
document.getElementById('connectButton').addEventListener('click', async () => {
//check if Metamask is installed
if (window.ethereum) {
const web3 = new Web3(window.ethereum);
// Request the user to connect accounts (Metamask will prompt)
await window.ethereum.request({ method: "eth_requestAccounts" });
await window.ethereum.request({ method: 'eth_requestAccounts' });
// Get the connected accounts
const accounts = await web3.eth.getAccounts();
// Display the connected account
document.getElementById("connectedAccount").innerText = accounts[0];
document.getElementById('connectedAccount').innerText = accounts[0];
} else {
// Alert the user to download Metamask
alert("Please download Metamask");
alert('Please download Metamask');
}
});
</script>
Expand Down
Loading

1 comment on commit cb6c434

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: cb6c434 Previous: 6c075db Ratio
processingTx 8624 ops/sec (±4.13%) 9301 ops/sec (±4.81%) 1.08
processingContractDeploy 38780 ops/sec (±7.47%) 39129 ops/sec (±7.62%) 1.01
processingContractMethodSend 18707 ops/sec (±7.97%) 19443 ops/sec (±5.19%) 1.04
processingContractMethodCall 38107 ops/sec (±5.77%) 38971 ops/sec (±6.34%) 1.02
abiEncode 43036 ops/sec (±7.76%) 44252 ops/sec (±6.92%) 1.03
abiDecode 30192 ops/sec (±7.18%) 30419 ops/sec (±8.89%) 1.01
sign 1608 ops/sec (±1.27%) 1656 ops/sec (±4.08%) 1.03
verify 365 ops/sec (±0.63%) 373 ops/sec (±0.78%) 1.02

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.