Skip to content

Commit

Permalink
Merge branch '4.x' into 6609
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex authored Jan 3, 2024
2 parents 47bc7dc + 6c075db commit d4621f2
Show file tree
Hide file tree
Showing 45 changed files with 1,816 additions and 205 deletions.
83 changes: 73 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- run: yarn prebuild
- run: yarn build:cjs
- run: tar -czf /tmp/web3-${{ matrix.node }}.js.tar.gz --exclude="./.git" ./
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: web3-${{ matrix.node }}.js.tar.gz
path: /tmp/web3-${{ matrix.node }}.js.tar.gz
Expand All @@ -42,7 +42,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: web3-${{ matrix.node }}.js.tar.gz
path: /tmp
Expand All @@ -59,7 +59,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: web3-${{ matrix.node }}.js.tar.gz
path: /tmp
Expand All @@ -73,7 +73,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 18
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: web3-18.js.tar.gz
path: /tmp
Expand All @@ -88,7 +88,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 18
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: web3-18.js.tar.gz
path: /tmp
Expand Down Expand Up @@ -128,7 +128,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: web3-${{ matrix.node }}.js.tar.gz
path: /tmp
Expand Down Expand Up @@ -158,7 +158,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: web3-${{ matrix.node }}.js.tar.gz
path: /tmp
Expand All @@ -183,7 +183,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: web3-${{ matrix.node }}.js.tar.gz
path: /tmp
Expand All @@ -206,7 +206,7 @@ jobs:
node-version: ${{ matrix.node }}
- uses: browser-actions/setup-firefox@latest
if: matrix.browser == 'firefox'
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: web3-${{ matrix.node }}.js.tar.gz
path: /tmp
Expand All @@ -230,9 +230,72 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: web3-${{ matrix.node }}.js.tar.gz
path: /tmp
- run: tar -xf /tmp/web3-${{ matrix.node }}.js.tar.gz -C ./
- run: yarn build:docs

benchmark:
name: Benchmark Tests
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
node: [ 18 ]
steps:
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- uses: actions/download-artifact@v4
with:
name: web3-${{ matrix.node }}.js.tar.gz
path: /tmp
- run: tar -xf /tmp/web3-${{ matrix.node }}.js.tar.gz -C ./
# @octokit/core not supported on node 16, so I can't add it to the package.json
- run: npm install --no-package-lock --no-save --force @octokit/core
- name: Restore main branch benchmark data
uses: actions/cache/restore@v3
with:
path: web3-benchmark-main.json
key: ${{ runner.os }}-web3-benchmark-main.json
- run: yarn test:benchmark
- name: Compare benchmark result and make comment
uses: benchmark-action/github-action-benchmark@v1
with:
# What benchmark tool the output.txt came from
tool: 'benchmarkjs'
# Where the output from the benchmark tool is stored
output-file-path: benchmark-data.txt
# Where the previous data file is stored
external-data-json-path: web3-benchmark-main.json
# Workflow will fail when an alert happens
fail-on-alert: false
# GitHub API token to make a commit comment
github-token: ${{ secrets.GITHUB_TOKEN }}
# Enable alert commit comment
comment-always: true
save-data-file: false
# copy comment from commit to Pull Request
- run: node scripts/copyCommitCommentToPrComment.js ${{ secrets.GITHUB_TOKEN }} ${{github.event.pull_request.head.sha}} ${{github.event.number}}
- name: Compare benchmark result and fail if threshold is reached
uses: benchmark-action/github-action-benchmark@v1
with:
# What benchmark tool the output.txt came from
tool: 'benchmarkjs'
# Where the output from the benchmark tool is stored
output-file-path: benchmark-data.txt
# Where the previous data file is stored
external-data-json-path: web3-benchmark-main.json
# Workflow will fail when an alert happens
fail-on-alert: true
# Enable alert commit comment
alert-threshold: '100%'
comment-always: false
- name: Save main branch benchmark data
uses: actions/cache/save@v3
if: github.event_name == 'push' && github.ref == 'refs/heads/4.x'
with:
path: web3-benchmark-main.json
key: ${{ runner.os }}-web3-benchmark-main.json
4 changes: 2 additions & 2 deletions .github/workflows/deploy-docs.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Docs CloudFlare Deploy
on:
on:
push:
branches-ignore:
- "1.x"
Expand All @@ -25,4 +25,4 @@ jobs:
accountId: 2238a825c5aca59233eab1f221f7aefb
projectName: web3-js-docs
directory: ./docs/build
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ tmp/

# Incubed (in3) nodelist
packages/web3/.in3/

# benchmark results
benchmark-data.txt
5 changes: 5 additions & 0 deletions docs/docs/guides/smart_contracts/_category_.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
label: 'Smart Contracts'
collapsible: true
collapsed: true
link: null
position: 4
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
sidebar_position: 1
sidebar_label: 'Deploying and Interacting with Smart Contracts'
sidebar_label: 'Tutorial: Deploying and Interacting with Smart Contracts'
---

import Tabs from '@theme/Tabs';
Expand All @@ -24,6 +24,12 @@ Here is a high-level overview of the steps we will be taking in this tutorial:
6. Deploy the smart contract to the Ganache network using web3.js.
7. Interact with the smart contract using web3.js.

:::tip
📝 **Community support:**
If you encounter any issues while following this guide or have questions, don't hesitate to seek assistance. Our friendly community is ready to help you out!
Join our [Discord](https://discord.gg/F4NUfaCC) server and head to the **#web3js-general** channel to connect with other developers and get the support you need.
:::

## Step 1: Setting up the Environment

Before we start writing and deploying our contract, we need to set up our environment. For that, we need to install the following:
Expand Down Expand Up @@ -108,9 +114,9 @@ Next, create a new file called `compile.js` in your project directory and add th
// This code will compile smart contract and generate its ABI and bytecode
// Alternatively, you can use something like `npm i solc && npx solcjs MyContract.sol --bin --abi`

import solc from 'solc';
import path from 'path';
import fs from 'fs';
const solc = require( 'solc');
const path = require('path');
const fs = require('fs');

const fileName = 'MyContract.sol';
const contractName = 'MyContract';
Expand Down Expand Up @@ -340,20 +346,20 @@ async function deploy() {
const defaultAccount = providersAccounts[0];
console.log('deployer account:', defaultAccount);

const deployedContract = myContract.deploy({
const contractDeployer = myContract.deploy({
data: '0x' + bytecode,
arguments: [1],
});

// optionally, estimate the gas that will be used for development and log it
const gas = await deployedContract.estimateGas({
const gas = await contractDeployer.estimateGas({
from: defaultAccount,
});
console.log('estimated gas:', gas);

try {
// Deploy the contract to the Ganache network
const tx = await deployedContract.send({
const tx = await contractDeployer.send({
from: defaultAccount,
gas,
gasPrice: 10000000000,
Expand Down Expand Up @@ -396,18 +402,18 @@ async function deploy(): Promise<void> {
const defaultAccount: string = providersAccounts[0];
console.log('deployer account:', defaultAccount);

const deployedContract: any = myContract.deploy({
const contractDeployer: any = myContract.deploy({
data: '0x' + bytecode,
arguments: [1],
});

const gas: number = await deployedContract.estimateGas({
const gas: number = await contractDeployer.estimateGas({
from: defaultAccount,
});
console.log('estimated gas:', gas);

try {
const tx: any = await deployedContract.send({
const tx: any = await contractDeployer.send({
from: defaultAccount,
gas,
gasPrice: 10000000000,
Expand Down
Loading

1 comment on commit d4621f2

@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: d4621f2 Previous: 6c075db Ratio
processingTx 9256 ops/sec (±3.93%) 9301 ops/sec (±4.81%) 1.00
processingContractDeploy 38479 ops/sec (±12.23%) 39129 ops/sec (±7.62%) 1.02
processingContractMethodSend 20124 ops/sec (±5.05%) 19443 ops/sec (±5.19%) 0.97
processingContractMethodCall 39428 ops/sec (±6.04%) 38971 ops/sec (±6.34%) 0.99
abiEncode 45129 ops/sec (±7.02%) 44252 ops/sec (±6.92%) 0.98
abiDecode 31583 ops/sec (±9.63%) 30419 ops/sec (±8.89%) 0.96
sign 1652 ops/sec (±5.17%) 1656 ops/sec (±4.08%) 1.00
verify 379 ops/sec (±0.56%) 373 ops/sec (±0.78%) 0.98

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

Please sign in to comment.