Closed louloub closed 1 year ago
@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
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
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'
);
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 ?
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
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
}
},
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
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 :)
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
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
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
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)
./resume.sh
from the blockchain foldercontract Test { uint public count;
}
This is the genesis file of it :
node public_tx.js
This is the content of the file :// 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 serializedTx:
Just after these console.log i have a error :
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)
besu --version
] : using dockerimage: hyperledger/besu:${BESU_VERSION:-latest}
java -version
]cat /etc/*release
] : Ubuntu 22.04.1 LTSuname -a
] : Linux blockchain 5.15.0-52-generic #58-Ubuntu SMP Thu Oct 13 08:03:55 UTC 2022 x86_64 x86_64 x86_64 GNU/Linuxvmware -v
]docker version
] : 20.10.12Smart contract information (If you're reporting an issue arising from deploying or calling a smart contract, please supply related information)
solc --version
] : Version: 0.8.21+commit.d9974bed.Linux.g++Additional Information (Add any of the following or anything else that may be relevant)