Web3BB

    • Register
    • Login
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    1. Home
    2. web3master
    W
    • Profile
    • Following 0
    • Followers 0
    • Topics 13
    • Posts 13
    • Best 0
    • Controversial 0
    • Groups 1

    web3master

    @web3master

    0
    Reputation
    1
    Profile views
    13
    Posts
    0
    Followers
    0
    Following
    Joined Last Online
    Website web3bb.com Location earth

    web3master Unfollow Follow
    administrators

    Latest posts made by web3master

    • Hardhat Ganache-cli ProviderError: HttpProviderError http.ts:78:19

      I am using ganache-cli with mainnet fork, but I use Hardhat with Ethers library to deploy the contract.

      Here is an example:

      Contract Code (HelloWorld.sol):

      // SPDX-License-Identifier: MIT
      pragma solidity <=0.8.10;
      
      contract HelloWorld {
      
          string saySomething;
      
          constructor() {
              saySomething = "Hello World!";
          }
      
          function speak() public view returns(string memory) {
              return saySomething;
          }
      }
      

      Deployment Code:

      const { ethers } = require("hardhat");
      const config = require("../config.json")
      const fs = require('fs');
      
      async function main() {
      
      	const [deployer] = await ethers.getSigners();
      
      	console.log(
      	"Deploying contracts with the account:",
      	deployer.address
      	);
      
      	console.log("Account balance:", (await deployer.getBalance()).toString());
      
      	const HelloWorld = await ethers.getContractFactory("HelloWorld");
      	const contract = await HelloWorld.deploy();
      
      	console.log("Contract deployed at:", contract.address);
      }
      
      main()
        .then(() => process.exit(0))
        .catch(error => {
      	console.error(error);
      	process.exit(1);
        });
      

      Deployment Output:

      npx hardhat --network ganache  run scripts/deployHelloWorld.js
      
      Deploying contracts with the account: 0x3244e66158295043AF04548925EbaE25cCC73c8F
      Account balance: 1000000000000000000000
      ProviderError: HttpProviderError
          at HttpProvider.request (/Users/dapp/node_modules/hardhat/src/internal/core/providers/http.ts:78:19)
          at LocalAccountsProvider.request (/Users/dapp/node_modules/hardhat/src/internal/core/providers/accounts.ts:181:36)
          at processTicksAndRejections (node:internal/process/task_queues:96:5)
          at EthersProviderWrapper.send (/Users/dapp/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)
      

      adding:

        try {
          const contract = await HelloWorld.deploy();
        } catch (e) {
            console.log(e.message);
            throw e;
        }
      

      It gives more info:

      npx hardhat --network ganache  run scripts/deployHelloWorld.js
      Deploying contracts with the account: 0x3244e66158295043AF04548925EbaE25cCC73c8F
      Account balance: 1000000000000000000000
      VM Exception while processing transaction: Transaction's maxFeePerGas (2000000000) is less than the block's baseFeePerGas (7978231074) (vm hf=london -> block -> tx)
      

      Solution

      add gasPrice: 50000000000
      to hardhat.config.js

        networks: {
          ganache: {
            gasPrice: 50000000000,
            url: "http://127.0.0.1:7545",
            accounts: [privateKey]
          }
        }
      
      posted in Ethers
      W
      web3master
    • BNB Validator config

      exec geth
      --config /config/config.mainnet.toml
      --syncmode "snap"
      --gcmode "full"
      --http
      --http.addr 0.0.0.0
      --http.corsdomain ""
      --http.api eth,admin,net,web3,debug
      --http.port "8545"
      --http.vhosts '
      '
      --maxpeers "250"
      --ws
      --ws.addr 0.0.0.0
      --ws.origins "*"
      --ws.port "8545"
      --metrics
      --pprof
      --pprof.addr 0.0.0.0
      --pprof.port "6060"
      --datadir /ethereum
      --keystore /ethereum/keystore
      --cache "32000"
      --networkid "56"
      --txlookuplimit 1024
      --verbosity "3"
      --unlock "${CONSENSUS_ADDRESS}"
      --password /ethereum/keystore/consensus-keystore-password.txt
      --allow-insecure-unlock
      --mine
      $} }(tee -a /var/log/node/bsc.log)

      Config:

      [Eth]
      NetworkId = 56
      NoPruning = false
      NoPrefetch = false
      LightPeers = 0
      UltraLightFraction = 75
      TrieTimeout = 100000000000
      EnablePreimageRecording = false
      EWASMInterpreter = ""
      EVMInterpreter = ""
      [Eth.Miner]
      GasFloor = 30000000
      GasCeil = 40000000
      GasPrice = 5000000000
      Recommit = 10000000000
      Noverify = false
      [Eth.TxPool]
      Locals = []
      NoLocals = true
      Journal = "transactions.rlp"
      Rejournal = 3600000000000
      PriceLimit = 5000000000
      PriceBump = 10
      AccountSlots = 512
      GlobalSlots = 10000
      AccountQueue = 256
      GlobalQueue = 5000
      Lifetime = 10800000000000
      [Eth.GPO]
      Blocks = 20
      Percentile = 60
      OracleThreshold = 20
      [Node]
      IPCPath = "geth.ipc"
      HTTPHost = "localhost"
      NoUSB = true
      InsecureUnlockAllowed = true
      HTTPPort = 8545
      HTTPVirtualHosts = ["localhost"]
      HTTPModules = ["eth", "admin", "net", "web3", "txpool", "parlia"]
      WSPort = 8546
      WSModules = ["net", "web3", "eth"]
      [Node.P2P]
      NoDiscovery = false
      # StaticNodes = [" removed for clarity "]
      #ListenAddr = ":30311"
      EnableMsgEvents = false
      [Node.HTTPTimeouts]
      ReadTimeout = 30000000000
      WriteTimeout = 30000000000
      IdleTimeout = 120000000000
      config.testnet.toml: |-
      [Eth]
      NetworkId = 97
      NoPruning = false
      NoPrefetch = false
      LightPeers = 0
      UltraLightFraction = 75
      EnablePreimageRecording = false
      EWASMInterpreter = ""
      EVMInterpreter = ""
      [Eth.Miner]
      GasFloor = 140000000
      GasCeil = 140000000
      GasPrice = 1000000000
      Recommit = 10000000000
      Noverify = false
      [Eth.TxPool]
      Locals = []
      NoLocals = true
      Journal = "transactions.rlp"
      Rejournal = 3600000000000
      PriceLimit = 1000000000
      PriceBump = 10
      AccountSlots = 16
      GlobalSlots = 4096
      AccountQueue = 64
      GlobalQueue = 1024
      Lifetime = 10800000000000
      [Eth.GPO]
      Blocks = 20
      Percentile = 60
      [Node]
      InsecureUnlockAllowed = true
      NoUSB = true
      IPCPath = "geth.ipc"
      HTTPHost = "127.0.0.1"
      HTTPPort = 8575
      HTTPVirtualHosts = ["*"]
      HTTPModules = ["debug", "eth", "admin", "net", "web3", "txpool", "parlia"]
      WSPort = 8576
      WSModules = ["net", "web3", "eth"]
      [Node.P2P]
      NoDiscovery = false
      StaticNodes = ["removed for clarity"]'

      posted in BNB Smart Chain
      W
      web3master
    • BSC Fast Node

      https://github.com/bnb-chain/bsc/pull/926

      posted in BNB Smart Chain
      W
      web3master
    • BNB Archive Node with Erigon

      BNB Archive Node with Erigon

      https://github.com/allada/bsc-archive-snapshot/blob/master/build_archive_node.sh

      https://github.com/ledgerwatch/erigon/releases/tag/v2.31.0-rc.2

      posted in BNB Smart Chain
      W
      web3master
    • Fork Uniswap

      https://medium.com/@maxime.atton/fork-uniswap-v2-smart-contracts-ui-on-remix-e885d6cea176

      posted in Solidity
      W
      web3master
    • How to Receive ERC20 In smart Contract
      //SPDX-License-Identifier: MIT
      pragma solidity 0.8.0;
      
      import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
      import "@openzeppelin/contracts/access/Ownable.sol";
      
      contract Orders is Ownable {
        uint256 public counter;
        address token;
      
        constructor(address _token) {
          token = _token;
        }
      
        function deposit(uint _amount) public payable {
          // Set the minimum amount to 1 token (in this case I'm using LINK token)
          uint _minAmount = 1*(10**18);
          // Here we validate if sended USDT for example is higher than 50, and if so we increment the counter
          require(_amount >= _minAmount, "Amount less than minimum amount");
          // I call the function of IERC20 contract to transfer the token from the user (that he's interacting with the contract) to
          // the smart contract  
          IERC20(token).transferFrom(msg.sender, address(this), _amount);
          counter = counter + 1;
        }
      
        // This function allow you to see how many tokens have the smart contract 
        function getContractBalance() public onlyOwner view returns(uint){
          return IERC20(token).balanceOf(address(this));
        }
      }
      
      posted in Solidity
      W
      web3master
    • Flashbots alternative for Binance Smart Chain

      https://directroute.nodereal.io/

      https://docs.bnb48.club/buidl/infrastructure/bsc-validator/enhanced-rpc/puissant-api

      posted in BNB Smart Chain
      W
      web3master
    • Running BNB Smart Chain GETH on Docker

      Running BNB Smart Chain Node in a Docker Container

      Description
      This document describes the process of configuring and running a BNB Smart Chain node (geth) using the docker container image from the official git repository.

      Prerequisites
      Server/Computer with at least 300GB+ of free disk space for testnet node
      Docker
      Official Docker Image

      Introduction to Docker
      Docker is a tool that makes it easier for developers to create and deliver applications in containers. Containers allow developers to put an application with all of its requirements, such as libraries and other dependencies and deploy it as a single image. When running the application the user doesn’t need to know all the requirements to run a specific application, because it is all bundled together in this image. Basically when you are inside of a container you feel like you are in a completely different host, it feels like a Virtual Machine but it is actually not. Each container shares the kernel within the host OS, allowing you to run multiple Docker containers on the same host.
      https://www.docker.com/

      Introduction to BSC Node
      A node is basically a blockchain software that runs on the computer/server, when this software is started it will make a copy of the entire blockchain to your local machine and it will broadcast its data to the blockchain network helping it by serving the network with data.

      Why run your own node?
      Not for Rewards

      Nodes that are not validators do not receive any reward because they are not validating blocks.

      Trust and Privacy
      Running your own node enables you to use BNB Smart Chain in a private, self-sufficient and trustless manner. You don't need to trust the network because you can verify the data yourself with your client.

      Potential Better Performance
      You have the control to decide what hardware specification you will build you own node on. This way you can potentially get better performance.
      No limits and More data
      When using public Nodes, specially for Dapps, the nodes have limits on the amount of calls you can make to the node. Also not all data is provided with public nodes, if you run your own node you can expose to yourself all the data from the blockchain, and be able to monitor things such as the transactions mem pool.

      Docker Installation
      https://docs.docker.com/get-docker/

      Desktop Users:
      https://docs.docker.com/get-docker/

      Ubuntu Linux:
      https://docs.docker.com/engine/install/ubuntu/

      Post install:

      Start docker during boot up:

      systemctl enable docker.service
      systemctl enable containerd.service

      Add user "ubuntu" to group docker so the user has privileges to run docker commands:

      sudo usermod -aG docker $USER

      Login: tsh ssh ubuntu@172.21.42.10
      Download Docker Container
      Instructions: https://github.com/bnb-chain/bsc/pkgs/container/bsc
      docker pull ghcr.io/bnb-chain/bsc:1.1.18_hf

      Important commands:
      List images available on your Docker host.

      $ docker images

      List running containers

      $ docker ps

      List stopped containers

      $ docker ps -a

      Check container logs

      $ docker logs containerName or ContainerID

      Show container details

      $ docker inspect containerName or ContainerID

      Shell access container
      $ docker exec -it containerName bash

      Node configuration
      Download Testnet or Mainnet config files

      Reference: https://docs.bnbchain.org/docs/validator/fullnode

      Create Directories
      mkdir -p ~/bsc/config
      mkdir -p ~/bsc/node

      if you are not running as root open permissions to node directory, this will permit that docker container create data under the node folder

      chmod 777 ~/bsc/node
      cd ~/bsc/config
      wget $(curl -s https://api.github.com/repos/bnb-chain/bsc/releases/latest |grep browser_ |grep testnet |cut -d" -f4)
      unzip testnet.zip
      cd ~/bsc

      PS: Don’t need to write genesis state
      Start Container

      $ docker run (options) imageName

      Example:
      $ docker run -d --name bsccontainer01 -v ~/bsc/node:/bsc/node -v ~/bsc/config:/bsc/config ghcr.io/bnb-chain/bsc:1.1.18_hf

      Options
      -d -> Detached from the screen. It will run the container in the background.
      –name -> name of the container
      -v -> For volume, in our case we are going to be binding our local disk to certain directories inside of the container

      -v ~/bsc/node:/bsc/nod -> Local ~/bsc/node will be mounted on /bsc/node in the container
      ~/bsc/config:/bsc/config -> Local ~/bsc/config directory will be mounted on /bsc/config in the container

      Check if container is running

      $ docker ps

      If it is running you can check the logs/output of the startup command

      $ docker logs bsccontainer01

      Check blockchain data logs
      docker exec -it bsccontainer01 tail -f node/bsc.log

      Connect to local Javascript interface using IPC and check synchronization status
      docker exec -it bsccontainer01 geth attach ipc:node/geth.ipc

      eth.syncing

      How to shell into the Container:
      $ docker exec -it bsccontainer01 bash

      How to expose HTTP Json RPC?

      Stop/start container
      $ docker stop bsccontainer01

      $ docker start bsccontainer01

      Remove container
      $ docker rm bsccontainer01

      Edit config.toml
      -> HTTPHost = "0.0.0.0"

      Run container with exposing RPC port to host
      $ docker run -d --name bsccontainer01 -p 8575:8575 -v ~/bsc/node:/bsc/node -v ~/bsc/config:/bsc/config ghcr.io/bnb-chain/bsc:1.1.18_hf

      Note: By default testnet configuration runs http json-rpc server on port 8575.
      -p 8575:8575 -> we are exposing port 8575 to the host that is running docker and it will map with port 8575 that is open in the container.
      After we run this you will be able to reach the http json rpc on port 8575 of the host such as follows:
      $ geth attach http://HOST_IP:8575

      How to make changes in the configuration or set geth flags?
      In order to pass custom changes (flag) to geth you can just need to add the flags to the end of the docker run command as follows:
      Stop container
      $ docker stop bsccontainer01

      Remove container
      $ docker rm bsccontainer01

      Run container with desired flags. The following example shows how to enable websocket and expose the websocket port.
      $ docker run -d --name bsccontainer01 -p 3335:3335 -p 8575:8575 -v ~/bsc/node:/bsc/node -v ~/bsc/config:/bsc/config ghcr.io/bnb-chain/bsc:1.1.18_hf --ws.port 3335 --ws.addr 0.0.0.0 --ws --ws.api eth,net,web3 --ws.origins "*"

      Test connection
      ./geth attach ws://172.21.42.10:3335
      Docker Compose
      Docker compose will help maintain the configuration of the docker, it will make it easier to start and shutdown your containers.
      “Docker run is entirely command line based, while docker-compose reads configuration data from a YAML file”
      Add the following to a docker-compose.yml file:
      Vi docker-compose.yml
      version: '3.6'
      services:
      bscnode:
      image: ghcr.io/bnb-chain/bsc:1.1.18_hf
      command: --ws.port 3335 --ws.addr 0.0.0.0 --ws --ws.api eth,net,web3 --ws.origins "*"
      restart: unless-stopped
      container_name: bsccontainer01
      ports:
      - 8575:8575
      - 3335:3335
      volumes:
      - ~/bsc/node:/bsc/node
      - ~/bsc/config:/bsc/config

      Stop Old Container and Remove
      docker stop bsccontainer01
      docker rm bsccontainer01

      Using Docker compose to control your container.

      Start
      $ docker compose up -d

      Stop (this will remove the container)
      $ docker compose down

      Extra Resources:
      https://confluence.toolsfdg.net/display/Technology/BNB+Smart+Chain+Docker+Runbook

      posted in BNB Smart Chain
      W
      web3master
    • BNB Smart Chain - Etheres Listen to Events on RPC

      Json RPC server needs to have eth_getLogs enabled

      const ethers = require("ethers");
      
      const abi = [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"},{"name":"_data","type":"bytes"}],"name":"transferAndCall","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_subtractedValue","type":"uint256"}],"name":"decreaseApproval","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_addedValue","type":"uint256"}],"name":"increaseApproval","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"},{"indexed":false,"name":"data","type":"bytes"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"}]
      
      
      async function main() {
        const tokenAddress = "0xce3f1c9f2fd7e8edcc38ab0414fbc7292e7d372f";
        const provider = new ethers.providers.JsonRpcProvider("https://bsc-mainnet.nodereal.io/v1/64a9df0874fb4a93b9d0a3849de012d3", {
          name: "binance",
          chainId: 56,
        })
        const contract = new ethers.Contract(tokenAddress, abi, provider);
        contract.on("Transfer", (from, to, value, event) => {
          let info = {
            from: from,
            to: to,
            value: ethers.utils.formatUnits(value, 6),
            data: event,
          };
          console.log(JSON.stringify(info, null, 4));
        });
      }
      main();
      
      posted in Web3JS ethers rpc events bsc
      W
      web3master
    • Common BNB Chain Start up Flags

      Docker Full Node with validator option, open websockets, open HTTP JSON RPC, metrics, Influx DB, very vunerable, mostly to test things in a lab on testnet.

      docker run -d --name myBSCNode --network=myNetwork -p 8575:8575 -p 3335:3335 -p 6060:6060 -v /home/andremosin/bscnode:/bsc/node -v /home/andremosin/config:/bsc/config ghcr.io/bnb-chain/bsc:1.1.18_hf --cache 4000 --http --http.addr 0.0.0.0 --syncmode snap -unlock 0x18541766BE8dc9d53D76846EBf6B8b17620Ba0cd --password /bsc/config/accounts/password.txt --mine --allow-insecure-unlock --metrics --metrics.influxdb --metrics.influxdb.endpoint "http://influxdb:8086" --metrics.influxdb.username "geth" --metrics.influxdb.password "aq1sw2de3" --ws.port 3335 --ws.addr 0.0.0.0 --ws --ws.api eth,net,web3 --ws.origins "*" --rpc.allow-unprotected-txs
      

      Full Archive node from Genesis (needs 40+TB)

      sample cmd:

      ./geth --config local_config_dir/config.toml --datadir local_data_dir --pprof.addr 0.0.0.0 --rpc.allow-unprotected-txs --rpccorsdomain * --light.serve 50 --cache 5000 --metrics --snapshot=true --rangelimit --gcmode archive --txlookuplimit 0 --syncmode full --pprof
      
      posted in BNB Smart Chain
      W
      web3master