Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web3ValidatorError error when use sendSignedTransaction on HB blockchain #5812

Closed
louloub opened this issue Aug 28, 2023 · 11 comments
Closed
Assignees
Labels
bug Something isn't working non mainnet (private networks) not related to mainnet features - covers privacy, permissioning, IBFT2, QBFT TeamGroot GH issues worked on by Groot Team

Comments

@louloub
Copy link

louloub commented Aug 28, 2023

Description

As an blockchain developper, i'm actualy working on smart contract ERC-721 POC. I have a Hyperledger Besu blockchain working on my VM with 4 nodes, built with Qorum Quickstart (https://besu.hyperledger.org/stable/private-networks/tutorials/quickstart). This blockchain is configured for 0 fees.
I can develop, build, deploy, use my contract on Remix connected on my Hyperldeger Besu blockchain, but when i want to deploy the same smart contract from Visual Studio Code i have some mistakes with the signature of my transaction for deploy the contract.

Acceptance Criteria

Can build and sign my transaction for deploy the contract on my Hyperledger Besu blockchain.

Steps to Reproduce (Bug)

  1. Launch Hyperledger Besu blockchain with ./resume.sh from the blockchain folder
  2. Compile my smart contract and retrieve BIN, ABI and JSON files from bash script. Truffle dependencies on my VIsual Code had never worked, it's why i'm using this script.
    Contract code on Test.sol :
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

contract Test {
    uint public count;

    function increment() external {
        count += 1;
    }
}

command to launch the script :
./compile.sh contract.sol
bash script :

fileNameWithoutpath=$(basename $1)
#retrive file name without extension
fileNameWithoutPathAndExtension=${fileNameWithoutpath%.*}

echo "${bold}*************************************"
echo "Compile smart contract to BIN and ABI files from SOL files"
echo "*************************************${normal}"
solcjs --bin --abi $1 -o ../../build/contracts/
echo "fileNameWithoutPathAndExtension => $fileNameWithoutPathAndExtension"
solc $1 --combined-json abi,bin > ../../build/contracts/$fileNameWithoutPathAndExtension.json

for file in ../../build/contracts/*; do
    # Rename each file from this folder
    mv "$file" "../../build/contracts/${file##*_}"
done 
  1. Once my contract was built, i want to create transaction to deploy it on my Heperldger Besu Blockchain.

This is the genesis file of it :

{
    "config" : {
      "chainId" : 1337,
      "homesteadBlock": 0,
      "eip150Block": 0,
      "eip155Block": 0,
      "eip158Block": 0,
      "byzantiumBlock": 0,
      "constantinoplefixblock" : 0,
      "qbft": {
        "epochlength": 30000,
        "blockperiodseconds": 5,
        "requesttimeoutseconds": 10
      }
    },
    "nonce" : "0x0",
    "timestamp" : "0x58ee40ba",
    "gasLimit" : "0x1fffffffffffff",
    "difficulty" : "0x1",
    "number": "0x0",
    "gasUsed": "0x0",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "mixHash" : "0x63746963616c2062797a616e74696e65206661756c7420746f6c6572616e6365",
    "extraData": "0xf87aa00000000000000000000000000000000000000000000000000000000000000000f8549493917cadbace5dfce132b991732c6cda9bcc5b8a9427a97c9aaf04f18f3014c32e036dd0ac76da5f1894ce412f988377e31f4d0ff12d74df73b51c42d0ca9498c1334496614aed49d2e81526d089f7264fed9cc080c0",
    "coinbase" : "0x0000000000000000000000000000000000000000",
    "alloc" : { DELETED FOR THE GITHUB ISSUE }
  }
  1. I create my transaction, sign it and send it from the file "public_tx.js" called from this command : node public_tx.js
    This is the content of the file :
const { FeeMarketEIP1559Transaction } = require("@ethereumjs/tx");
// const Common = require("@ethereumjs/common").default;
const { Common, Chain, Hardfork } = require("@ethereumjs/common");
const ethUtil = require("ethereumjs-util");
const {Web3} = require("web3");
const path = require("path");
const fs = require("fs-extra");
const web3 = new Web3("http://0.0.0.0:8545");
const to = "0x0000000000000000000000000000000000009999"

// Define the network parameters
const chainId = 1337; // The chain ID of your Besu network
const hardfork = "london"; // The hardfork name of your Besu network

async function publicTx() {
  const customCommon = Common.custom({
    chainId: chainId,
    hardfork: hardfork
  });
  const account = web3.eth.accounts.privateKeyToAccount(
    "0x8f2a55949038a9610f50fb24b5883af3b4ecb3c3bb792cbcefbd1542c692be64",
    true
  );

  const contractJsonPath = path.resolve(
    __dirname,
    "../../build/contracts/Test.json"
  );
  const contractJson = JSON.parse(fs.readFileSync(contractJsonPath));
  const contractAbi = contractJson.abi;
  const contractBinPath = path.resolve(
    __dirname,
    "../../build/contracts/Test.bin"
  );
  const contractBin = fs.readFileSync(contractBinPath);
  const contractConstructorInit =
    "000000000000000000000000000000000000000000000000000000000000002F";

  const txnCount = await web3.eth.getTransactionCount(account.address);
  
  const dataBuild = "0x" + contractBin + contractConstructorInit
  console.log('dataBuild ==> ',dataBuild)

  const rawTxOptions = {
    nonce: web3.utils.numberToHex(txnCount),
    maxPriorityFeePerGas: "0x0", // The max priority fee per gas in wei
    maxFeePerGas: "0x0", // The max fee per gas in wei
    gasLimit: "0x186A0", // The gas limit in wei
    to: "0x0000000000000000000000000000000000009999", // The address of the contract you want to deploy
    value: "0x00", // The value in wei
    data: dataBuild
  };

  console.log('account ==> ', account)
  const privateKeyBuff = Buffer.from(
    account.privateKey,
    'hex'
  );

  const tx = FeeMarketEIP1559Transaction.fromTxData(rawTxOptions, { customCommon });
  
  const signedTx = tx.sign(privateKeyBuff);
  var serializedTx = signedTx.serialize();
  console.log("serializedTx ==> " ,serializedTx);

  const pTx = await web3.eth.sendSignedTransaction(
    "0x" + serializedTx.toString("hex").toString("hex")
  , function(error, receipt) {
    if (!error) {
      console.log('receipt => ' ,receipt)
    } else {
      console.log('error => ' ,error)

    }
  });
  console.log("tx transactionHash: " + pTx.transactionHash);
  console.log("tx contractAddress: " + pTx.contractAddress);
}

publicTx();

result of console.log for dataBuild :
0x608060405234801561000f575f80fd5b506101468061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610034575f3560e01c806306661abd14610038578063d09de08a14610056575b5f80fd5b610040610060565b60405161004d9190610097565b60405180910390f35b61005e610065565b005b5f5481565b60015f8082825461007691906100dd565b92505081905550565b5f819050919050565b6100918161007f565b82525050565b5f6020820190506100aa5f830184610088565b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f6100e78261007f565b91506100f28361007f565b925082820190508082111561010a576101096100b0565b5b9291505056fea26469706673582212201c3c48dec99e9cf77132e4073590b6c55580f5c057b9a16678a26b3bd45b716c64736f6c63430008150033000000000000000000000000000000000000000000000000000000000000002F

result of console.log for account:

  address: '0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73',
  privateKey: '0x8f2a55949038a9610f50fb23b5884af3b4ecb3c3bb792cbcefbd1542c692be64',
  signTransaction: [Function: signTransaction],
  sign: [Function: sign],
  encrypt: [Function: encrypt]
}

result of console.log for serializedTx:

Uint8Array(492) [
    2, 249,   1, 232,   1, 128, 128, 128, 131,   1, 134, 160,
  148,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
    0,   0,   0,   0,   0,   0,   0, 153, 153, 128, 185,   1,
  131,  96, 128,  96,  64,  82,  52, 128,  21,  97,   0,  15,
   87,  95, 128, 253,  91,  80,  97,   1,  70, 128,  97,   0,
   29,  95,  57,  95, 243, 254,  96, 128,  96,  64,  82,  52,
  128,  21,  97,   0,  15,  87,  95, 128, 253,  91,  80,  96,
    4,  54,  16,  97,   0,  52,  87,  95,  53,  96, 224,  28,
  128,  99,   6, 102,
  ... 392 more items

Just after these console.log i have a error :

/home/adminlogin/BESU_NETWORK/v5/contracts/EOBLOCK v2/node_modules/web3-validator/lib/commonjs/validator.js:73
                throw new errors_js_1.Web3ValidatorError(errors);
                      ^
Web3ValidatorError: Web3 validator found 1 error[s]:
value "0x2,249,1,232,1,128,128,128,131,1,134,160,148,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,153,153,128,185,1,131,96,128,96,64,82,52,128,21,97,0,15,87,95,128,253,91,80,97,1,70,128,97,0,29,95,57,95,243,254,96,128,96,64,82,52,128,21,97,0,15,87,95,128,253,91,80,96,4,54,16,97,0,52,87,95,53,96,224,28,128,99,6,102,26,189,20,97,0,56,87,128,99,208,157,224,138,20,97,0,86,87,91,95,128,253,91,97,0,64,97,0,96,86,91,96,64,81,97,0,77,145,144,97,0,151,86,91,96,64,81,128,145,3,144,243,91,97,0,94,97,0,101,86,91,0,91,95,84,129,86,91,96,1,95,128,130,130,84,97,0,118,145,144,97,0,221,86,91,146,80,80,129,144,85,80,86,91,95,129,144,80,145,144,80,86,91,97,0,145,129,97,0,127,86,91,130,82,80,80,86,91,95,96,32,130,1,144,80,97,0,170,95,131,1,132,97,0,136,86,91,146,145,80,80,86,91,127,78,72,123,113,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,95,82,96,17,96,4,82,96,36,95,253,91,95,97,0,231,130,97,0,127,86,91,145,80,97,0,242,131,97,0,127,86,91,146,80,130,130,1,144,80,128,130,17,21,97,1,10,87,97,1,9,97,0,176,86,91,91,146,145,80,80,86,254,162,100,105,112,102,115,88,34,18,32,28,60,72,222,201,158,156,247,113,50,228,7,53,144,182,197,85,128,245,192,87,185,161,102,120,162,107,59,212,91,113,108,100,115,111,108,99,67,0,8,21,0,51,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,47,192,128,160,52,50,225,140,187,125,5,209,45,142,251,176,206,178,8,64,131,49,4,73,77,57,12,182,167,170,7,151,166,172,88,15,160,8,244,95,158,148,147,217,202,246,101,194,121,38,108,83,78,161,148,56,68,231,33,13,173,150,83,21,75,44,115,17,222" at "/0" must pass "bytes" validation
    at Validator.validate (/home/adminlogin/BESU_NETWORK/v5/contracts/EOBLOCK v2/node_modules/web3-validator/lib/commonjs/validator.js:73:23)
    at Web3Validator.validate (/home/adminlogin/BESU_NETWORK/v5/contracts/EOBLOCK v2/node_modules/web3-validator/lib/commonjs/web3_validator.js:35:32)
    at bytesToUint8Array (/home/adminlogin/BESU_NETWORK/v5/contracts/EOBLOCK v2/node_modules/web3-eth/node_modules/web3-utils/lib/commonjs/converters.js:69:32)
    at hexToBytes (/home/adminlogin/BESU_NETWORK/v5/contracts/EOBLOCK v2/node_modules/web3-eth/node_modules/web3-utils/lib/commonjs/converters.js:114:42)
    at Object.<anonymous> (/home/adminlogin/BESU_NETWORK/v5/contracts/EOBLOCK v2/node_modules/web3-eth/lib/commonjs/rpc_method_wrappers.js:429:171)
    at Generator.next (<anonymous>)
    at /home/adminlogin/BESU_NETWORK/v5/contracts/EOBLOCK v2/node_modules/web3-eth/lib/commonjs/rpc_method_wrappers.js:24:71
    at new Promise (<anonymous>)
    at __awaiter (/home/adminlogin/BESU_NETWORK/v5/contracts/EOBLOCK v2/node_modules/web3-eth/lib/commonjs/rpc_method_wrappers.js:20:12)
    at /home/adminlogin/BESU_NETWORK/v5/contracts/EOBLOCK v2/node_modules/web3-eth/lib/commonjs/rpc_method_wrappers.js:426:20 {
  innerError: undefined,
  code: 1100,
  errors: [
    {
      keyword: '0',
      instancePath: '/0',
      schemaPath: '#0',
      params: {
        value: '0x2,249,1,232,1,128,128,128,131,1,134,160,148,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,153,153,128,185,1,131,96,128,96,64,82,52,128,21,97,0,15,87,95,128,253,91,80,97,1,70,128,97,0,29,95,57,95,243,254,96,128,96,64,82,52,128,21,97,0,15,87,95,128,253,91,80,96,4,54,16,97,0,52,87,95,53,96,224,28,128,99,6,102,26,189,20,97,0,56,87,128,99,208,157,224,138,20,97,0,86,87,91,95,128,253,91,97,0,64,97,0,96,86,91,96,64,81,97,0,77,145,144,97,0,151,86,91,96,64,81,128,145,3,144,243,91,97,0,94,97,0,101,86,91,0,91,95,84,129,86,91,96,1,95,128,130,130,84,97,0,118,145,144,97,0,221,86,91,146,80,80,129,144,85,80,86,91,95,129,144,80,145,144,80,86,91,97,0,145,129,97,0,127,86,91,130,82,80,80,86,91,95,96,32,130,1,144,80,97,0,170,95,131,1,132,97,0,136,86,91,146,145,80,80,86,91,127,78,72,123,113,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,95,82,96,17,96,4,82,96,36,95,253,91,95,97,0,231,130,97,0,127,86,91,145,80,97,0,242,131,97,0,127,86,91,146,80,130,130,1,144,80,128,130,17,21,97,1,10,87,97,1,9,97,0,176,86,91,91,146,145,80,80,86,254,162,100,105,112,102,115,88,34,18,32,28,60,72,222,201,158,156,247,113,50,228,7,53,144,182,197,85,128,245,192,87,185,161,102,120,162,107,59,212,91,113,108,100,115,111,108,99,67,0,8,21,0,51,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,47,192,128,160,52,50,225,140,187,125,5,209,45,142,251,176,206,178,8,64,131,49,4,73,77,57,12,182,167,170,7,151,166,172,88,15,160,8,244,95,158,148,147,217,202,246,101,194,121,38,108,83,78,161,148,56,68,231,33,13,173,150,83,21,75,44,115,17,222'
      },
      message: 'value "0x2,249,1,232,1,128,128,128,131,1,134,160,148,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,153,153,128,185,1,131,96,128,96,64,82,52,128,21,97,0,15,87,95,128,253,91,80,97,1,70,128,97,0,29,95,57,95,243,254,96,128,96,64,82,52,128,21,97,0,15,87,95,128,253,91,80,96,4,54,16,97,0,52,87,95,53,96,224,28,128,99,6,102,26,189,20,97,0,56,87,128,99,208,157,224,138,20,97,0,86,87,91,95,128,253,91,97,0,64,97,0,96,86,91,96,64,81,97,0,77,145,144,97,0,151,86,91,96,64,81,128,145,3,144,243,91,97,0,94,97,0,101,86,91,0,91,95,84,129,86,91,96,1,95,128,130,130,84,97,0,118,145,144,97,0,221,86,91,146,80,80,129,144,85,80,86,91,95,129,144,80,145,144,80,86,91,97,0,145,129,97,0,127,86,91,130,82,80,80,86,91,95,96,32,130,1,144,80,97,0,170,95,131,1,132,97,0,136,86,91,146,145,80,80,86,91,127,78,72,123,113,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,95,82,96,17,96,4,82,96,36,95,253,91,95,97,0,231,130,97,0,127,86,91,145,80,97,0,242,131,97,0,127,86,91,146,80,130,130,1,144,80,128,130,17,21,97,1,10,87,97,1,9,97,0,176,86,91,91,146,145,80,80,86,254,162,100,105,112,102,115,88,34,18,32,28,60,72,222,201,158,156,247,113,50,228,7,53,144,182,197,85,128,245,192,87,185,161,102,120,162,107,59,212,91,113,108,100,115,111,108,99,67,0,8,21,0,51,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,47,192,128,160,52,50,225,140,187,125,5,209,45,142,251,176,206,178,8,64,131,49,4,73,77,57,12,182,167,170,7,151,166,172,88,15,160,8,244,95,158,148,147,217,202,246,101,194,121,38,108,83,78,161,148,56,68,231,33,13,173,150,83,21,75,44,115,17,222" at "/0" must pass "bytes" validation'
    }
  ]
}

I maked some research on google but i don't find any topic with this error.

Expected behavior: can deploy my contract

Actual behavior: error displayed on console when sendSignedTransaction is used

Frequency: Every time i use this function

Logs (if a bug)

Please post relevant logs from Besu (and the consensus client, if running proof of stake) from before and after the issue.

Versions (Add all that apply)

  • Software version: [besu --version] : using docker image: hyperledger/besu:${BESU_VERSION:-latest}
  • Java version: [java -version]
  • OS Name & Version: [cat /etc/*release] : Ubuntu 22.04.1 LTS
  • Kernel Version: [uname -a] : Linux blockchain 5.15.0-52-generic Add default SECURITY policy #58-Ubuntu SMP Thu Oct 13 08:03:55 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
  • Virtual Machine software & version: [vmware -v]
  • Docker Version: [docker version] : 20.10.12
  • Cloud VM, type, size: [Amazon Web Services I3-large]
  • Consensus Client & Version if using Proof of Stake: [e.g. Teku, Lighthouse, Prysm, Nimbus, Lodestar] : using QBFT

Smart contract information (If you're reporting an issue arising from deploying or calling a smart contract, please supply related information)

  • Solidity version [solc --version] : Version: 0.8.21+commit.d9974bed.Linux.g++
  • Repo with minimal set of deployable/reproducible contract code - please provide a link : can't provide link with my companie safety rules
  • Please include specifics on how you are deploying/calling the contract : step 3
  • Have you reproduced the issue on other eth clients : smart contract can be build / compil / deploy and use on Remix connected to my blockchain with remixd

Additional Information (Add any of the following or anything else that may be relevant)

  • Besu setup info - genesis file, config options : Genesis provided on top of the issue
  • System info - memory, CPU : VM with 4 CPU / Go RAM / 150Go SSD
@non-fungible-nelson non-fungible-nelson added bug Something isn't working non mainnet (private networks) not related to mainnet features - covers privacy, permissioning, IBFT2, QBFT labels Aug 28, 2023
@siladu
Copy link
Contributor

siladu commented Aug 28, 2023

@louloub The latest fork in your genesis file is "constantinoplefixblock" : 0,
however the script uses FeeMarketEIP1559Transaction which requires the more recent londonBlock hard fork.

I would recommend upgrading your genesis to london or later.
Note, if you're using free gas with london, you need extra config:
https://besu.hyperledger.org/stable/private-networks/how-to/configure/free-gas#4-enable-zero-base-fee-if-using-london-fork-or-later

@siladu
Copy link
Contributor

siladu commented Aug 28, 2023

Also, are you using the latest version of quickstart? Because the latest version should already have this config built in https://github.com/Consensys/quorum-dev-quickstart/blob/master/files/besu/config/besu/QBFTgenesis.json#L14-L17

@siladu siladu self-assigned this Aug 28, 2023
@siladu siladu added the TeamGroot GH issues worked on by Groot Team label Aug 28, 2023
@siladu siladu assigned joshuafernandes and unassigned siladu Aug 29, 2023
@louloub
Copy link
Author

louloub commented Aug 29, 2023

Hi @siladu thanks for your answers !

I modified my genesis.json file like this and remove / run the blockchain, and i have the same error.

genesis.json :

"config" : {
      "chainId": 1337,
	    "homesteadBlock": 0,
	    "eip150Block": 0,
	    "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
	    "eip155Block": 0,
	    "eip158Block": 0,
	    "byzantiumBlock": 0,
	    "constantinopleBlock": 0,
	    "petersburgBlock": 0,
	    "istanbulBlock": 0,
	    "muirglacierblock": 0,
	    "berlinBlock": 0,
	    "londonBlock": 0,
	    "zeroBaseFee": true,
    	    "contractSizeLimit": 2147483647,
	    "qbft": {
	      "blockperiodseconds": 5,
	      "epochlength": 30000,
	      "requesttimeoutseconds": 10
	    }
    },
    "nonce" : "0x0",
    "timestamp" : "0x58ee40ba",
    "gasLimit" : "0x1fffffffffffff",
    "difficulty" : "0x1",
    "number": "0x0",
    "gasUsed": "0x0",
(....)

Just after i had a error about signature length, fixed with this udpated code :

const privateKeyBuff = Buffer.from(
    account.privateKey.substring(2,66),
    'hex'
  );

@louloub
Copy link
Author

louloub commented Aug 30, 2023

Hello !

I thought I had solved the problem with this line of code, but I have a new problem after this modification.

code line :

const result = Buffer.from(serializedTx).toString("hex");
const pTx = await web3.eth.sendSignedTransaction(
    result,
    function (error, receipt) {
      if (!error) {
        console.log("receipt ==> ", receipt);
      } else {
        console.log("error ==> ", error);
      }
    }
  );

new issue :

/home/adminlogin/BESU_NETWORK/v5/contracts/EOBLOCK v2/node_modules/web3-eth/lib/commonjs/utils/get_transaction_error.js:48
            error = new web3_errors_1.TransactionRevertInstructionError(_reason, undefined, transactionReceiptFormatted);
                    ^

TransactionRevertInstructionError: Transaction has been reverted by the EVM
    at /home/adminlogin/BESU_NETWORK/v5/contracts/EOBLOCK v2/node_modules/web3-eth/lib/commonjs/utils/get_transaction_error.js:48:21
    at Generator.next (<anonymous>)
    at /home/adminlogin/BESU_NETWORK/v5/contracts/EOBLOCK v2/node_modules/web3-eth/lib/commonjs/utils/get_transaction_error.js:24:71
    at new Promise (<anonymous>)
    at __awaiter (/home/adminlogin/BESU_NETWORK/v5/contracts/EOBLOCK v2/node_modules/web3-eth/lib/commonjs/utils/get_transaction_error.js:20:12)
    at getTransactionError (/home/adminlogin/BESU_NETWORK/v5/contracts/EOBLOCK v2/node_modules/web3-eth/lib/commonjs/utils/get_transaction_error.js:33:12)
    at Object.<anonymous> (/home/adminlogin/BESU_NETWORK/v5/contracts/EOBLOCK v2/node_modules/web3-eth/lib/commonjs/rpc_method_wrappers.js:441:100)
    at Generator.next (<anonymous>)
    at fulfilled (/home/adminlogin/BESU_NETWORK/v5/contracts/EOBLOCK v2/node_modules/web3-eth/lib/commonjs/rpc_method_wrappers.js:21:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  innerError: undefined,
  reason: 'Internal error',
  signature: undefined,
  receipt: undefined,
  data: undefined,
  code: 402
}

Does i create new issue on github ?

@joshuafernandes
Copy link
Contributor

Hello @louloub

Keep the thread here for now. I haven't quite figured out what's going on with web3, but have been ok deploying contracts with ethers.js

Something like this below works fine on Besu on the quickstart, hopefully will unblock you

const path = require('path');
const fs = require('fs-extra');
var ethers = require('ethers');

// RPCNODE details
const { tessera, besu } = require("../keys.js");
const host = besu.rpcnode.url;
const accountPrivateKey = besu.rpcnode.accountPrivateKey;

// abi and bytecode generated from simplestorage.sol:
// > solcjs --bin --abi simplestorage.sol
const contractJsonPath = path.resolve(__dirname, '../../','contracts','Test.json');
const contractJson = JSON.parse(fs.readFileSync(contractJsonPath));
const contractAbi = contractJson.abi;
const contractBytecode = contractJson.evm.bytecode.object

async function main(){
  const provider = new ethers.providers.JsonRpcProvider(host);
  const wallet = new ethers.Wallet(accountPrivateKey, provider);
  const nonce = await provider.getTransactionCount(wallet.address);
  const feeData = await provider.getFeeData();
  const gasLimit = await provider.estimateGas({from: wallet.address, value: ethers.utils.parseUnits("0.01", "ether")});
  var txn = {
    chainId: 1337,
    type: 2,
    nonce: nonce,
    to: "0x0000000000000000000000000000000000009999",
    value: ethers.utils.parseEther("0.01"),
    data: '0x'+contractBytecode,
    gasLimit: gasLimit,
    maxPriorityFeePerGas: feeData["maxPriorityFeePerGas"], 
    maxFeePerGas: feeData["maxFeePerGas"], 
  };
  const signedTx = await wallet.signTransaction(txn);
  provider.sendTransaction(signedTx).then(console.log);
}

if (require.main === module) {
  main();
}

module.exports = exports = main

Cheers
Josh

@louloub
Copy link
Author

louloub commented Sep 5, 2023

Hi @joshuafernandes !

Thanks for your time :)

I followed your code and modify some code line for finally deploy correctly my contract with ethers.js and can use one function ! (now i have another issue for using call function, i will create new issue i think)

This is my code :

const { ethers, JsonRpcProvider } = require("ethers");
const fs = require("fs");
const solFile = fs.readFileSync("../Test.sol", "utf8");
const solc = require("solc");

const provider = new JsonRpcProvider("http://localhost:8545");
const privateKey =
  "0x0ba970ff5e9b9c4ce2435fdf94a998af0b5892c4f6f7b9c3fcb0772ae98ab54";
const wallet = new ethers.Wallet(privateKey, provider);
const receiver = "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73";

buildContract();

async function buildContract() {
  const input = {
    language: "Solidity",
    sources: {
      "Test.sol": {
        content: solFile,
      },
    },
    settings: {
      outputSelection: {
        "*": {
          "*": ["*"],
        },
      },
    },
  };
  const output = JSON.parse(solc.compile(JSON.stringify(input)));
  const bytecode = output.contracts["Test.sol"]["Test"].evm.bytecode.object;
  const abi = output.contracts["Test.sol"]["Test"].abi;

  const factory3 = new ethers.ContractFactory(abi, bytecode, wallet);
  const nonce = await provider.getTransactionCount(wallet)
  const contractDeployed = await factory3.deploy({
    gasLimit: "0x4e85c",
    gasPrice: "0x0",
    nonce: nonce
  });

  console.log("contractDeployed ==> ", contractDeployed);

  const contractDeployedAddress = await contractDeployed.getAddress();
  console.log("contractDeployedAddress ==> ", contractDeployedAddress);
  
  const sampleContract = new ethers.Contract(
    contractDeployedAddress,
    abi,
    wallet
  );
  const tx = await sampleContract.increment({
    gasLimit: "0x4e85c",
    gasPrice: "0x0",
  });

  console.log("tx ==> " ,tx); 

EDIT : for this solution, i'm back to NO EIP1559 blockchain version, this is my genesis.json :

 "config" : {
      "chainId" : 1337,
      "homesteadBlock": 0,
      "eip150Block": 0,
      "eip155Block": 0,
      "eip158Block": 0,
      "byzantiumBlock": 0,
      "constantinoplefixblock" : 0,
      "qbft": {
        "epochlength": 30000,
        "blockperiodseconds": 5,
        "requesttimeoutseconds": 10
      }
    },

@joshuafernandes
Copy link
Contributor

Hi @louloub

Really good to hear :) I've added in some examples based on this specifically (EIP-1559) in the quickstart yesterday and got it to deploy & read + write https://github.com/Consensys/quorum-dev-quickstart/blob/master/files/besu/smart_contracts/scripts/public/hre_1559_public_tx.js

Have also stuck to the ethers type of calls and contractfactory (I find this abstractions nicer to work with). Let me know if this works for your token as well and feel free to submit a PR if its lacking functionality

Cheers
Josh

@louloub
Copy link
Author

louloub commented Sep 6, 2023

Hi @joshuafernandes

Thanks for your answer ! I just updated my previous comment because i forgot to preciss that i'm back to NO EIP1559 blockchain version. Actualy i can use Ethers.js to deploy contract from .sol files and use "increment" function . But i have issue for simple "call" function. I'm working on it and i will create new issue for this :)

@joshuafernandes
Copy link
Contributor

Hi @louloub

Sounds good! This one should work in the future if you need one that is EIP-1559 https://github.com/Consensys/quorum-dev-quickstart/blob/master/files/besu/smart_contracts/scripts/public/hre_1559_public_tx.js#L69 .

For a normal one this should get you going https://github.com/Consensys/quorum-dev-quickstart/blob/master/files/besu/smart_contracts/scripts/public/hre_public_tx.js#L53 I have a get/set operation after deployment. Let me know if that works, else create a new issue

Cheers

@siladu
Copy link
Contributor

siladu commented Sep 7, 2023

Thanks @joshuafernandes and @louloub for your comments - I think this issue can be resolved now. If not, feel free to reopen.

@louloub if the new issue is related to the quickstart scripts rather than Besu itself, then https://github.com/Consensys/quorum-dev-quickstart might be a better place for it

@siladu siladu closed this as completed Sep 7, 2023
@louloub
Copy link
Author

louloub commented Sep 8, 2023

Hi @joshuafernandes !

Back with new informations :)

On my previous message i say that i can deploy and use increment function but can't use call function. But after lot of test i can say that my contract was not deployed correctly. I don't understand how it's possible that i can use increment function...

When i add on this code the line after the contract factory line

const test = await contractDeployed.waitForDeployment();
console.log(test)

This error was triggered :

Error: transaction execution reverted (action="sendTransaction", data=null, reason=null, invocation=null, revert=null, transaction={ "data": "", "from": "0xd48ab4450681d37CbfbDcf21e0b1eE9405045A9F", "to": null }, receipt={ "_type": "TransactionReceipt", "blockHash": "0xf2f71da4fc4c820604b82eb23ab6d9dc5ab43a4ef45685b4db38e934eab40e53", "blockNumber": 128208, "contractAddress": "0xc6aB7ED563D09a3CE72d4e812b8DDc004e9661fA", "cumulativeGasUsed": "321628", "from": "0xd48ab4450681d37CbfbDcf21e0b1eE9405045A9F", "gasPrice": "0", "gasUsed": "321628", "hash": "0x429a6967d601a2b6c57b3366a86c62777b5d40088327e2efb3f2a2f80ebc42c2", "index": 0, "logs": [  ], "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "root": null, "status": 0, "to": null }, code=CALL_EXCEPTION, version=6.7.1)

We can see on the TransactionReceipt the status 0 for reverted transaction

So now the question is why my contract can be deployed.

Do you have any ideas ?

Thanks for your time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working non mainnet (private networks) not related to mainnet features - covers privacy, permissioning, IBFT2, QBFT TeamGroot GH issues worked on by Groot Team
Projects
None yet
Development

No branches or pull requests

4 participants