How to verify TransparentUpgradeableProxy which is deployed using create2? - blockchain

I have deployed an upgradable contract using a factory contract which its code is as fallows:
bytes memory bytecode = abi.encodePacked(
type(TransparentUpgradeableProxy).creationCode,
abi.encode(implementation, proxyAdmin, "")
);
assembly {
contractAddress := create2(
0,
add(bytecode, 32),
mload(bytecode),
salt
)
}
Everything is working fine. I did verify the implementation using hardhat but I can't verify the proxy itself. Hardhat gives me the following error:
Failed to verify TransparentUpgradeableProxy contract at addr: Bytecode does not match with the current version of TransparentUpgradeableProxy in the Hardhat Upgrades plugin.
Any ideas?
I tried the hardhat CLI tool for verification

Related

Using Hardhat to deploy smart contract to local Polygon node

I have followed this tutorial to learn how can I use HARDHAT to deploy a Smart Contract on a Polygon testnet (and it worked just fine).
Now I want to run some tests on my local Polygon blockchain instance which is running and working fine on my local computer (with 4 nodes). I know it works because I can operate over it via jsonRPC and gRPG, consulting balances, status, etc.
So, in my hardhat.config.js I have this settings:
require("#nomiclabs/hardhat-ethers");
module.exports = {
defaultNetwork: "matic",
networks: {
hardhat: {
},
matic: {
url: "http://localhost:10002"
}
},
solidity: {
version: "0.8.0",
settings: {
optimizer: {
enabled: true,
runs: 200
}
}
},
paths: {
sources: "./contracts",
tests: "./test",
cache: "./cache",
artifacts: "./artifacts"
},
mocha: {
timeout: 20000
}
}
I then compiled and tryed to deploy Hardhat's sample script:
$ npx hardhat compile
>Downloading compiler 0.8.0
>Compiled 2 Solidity files successfully
$ npx hardhat run scripts/sample-script.js --network matic
>ProviderError: the method eth_accounts does not exist/is not available
> at HttpProvider.request (/home/edu/projects/test-hardhat->polygon/node_modules/hardhat/src/internal/core/providers/http.ts:74:19)
> at GanacheGasMultiplierProvider.request (/home/edu/projects/test-hardhat->polygon/node_modules/hardhat/src/internal/core/providers/gas-providers.ts:312:34)
It seems Hardhat is calling the method eth_accounts which does not exist in my Polygon-Edge local blockchain.
What am I doing wrong?
Thanks in advance
good question... Ran into your question while troubleshooting the same issue. I'm running polygon-edge server --dev... and couldn't deploy smart contracts with hardhat or truffle. An alternative is to use Remix IDE and your wallet to deploy via Injected Web3 per the project's Does polygon-edge support smart contract? #411 discussion.
Deploy & Run Transactions within the Remix IDE, with selected environment with deploying via transaction.
Once completed you'll be able to review and approve the transaction within your wallet which in turn deploys the contract via transaction. Pause for a second and be vigilant of scammers, fake remix IDE clones, or incidentally deploying this transaction to a live network using real funds! With that said: how to import a network to Metamask if you have yet to do so. If you need an account with funds, what worked for me was importing into Metamask an account via private key for which I included premined currency. To retrieve the private key I referred to my validator node's data folder contained the private key at $data-dir/consensus/validator.key file.
Regarding the actual error and web3js.. The error message is accurate. If you revisit the polygon-edge docs referencing JSON RPC Commands note eth_accounts method call is missing. This is problematic for the underlying node modules relying on web3.eth.getAccounts() call setup for contract deployment, and in turn impacting truffle and hardhat.

Polygon: Solidity build failed for 'pragma solidity ^0.8.7' with chainlink

In polygon chain, the latest chainlink version not support.
If I remove chainlink library, it deploy sucessfully.
Chainlink 0.8 working fine in 'ropston test' network. But in 'Mumbai test net', not able to deploy contract.
hardhat.config.js [edit:1]
error log:
remix error log:
You can deploy the contract with Remix Ide Online, web3 connection with Metamask.
Can you share your hardhat config file or error logs?
This should be inside your hardhat env.
mumbai: {
url: "https://rpc-mumbai.matic.today",
// url: API_URL, //or Infura API URL
accounts: [`0x${PRIVATE_KEY}`],
gasPrice: 10000000000,
gasLimit: 9000000
},
Edit: It's failing because cant estimate gasLimit of the transaction. You can set it manually.
Inside your deploy.js script set the gasPrice and gasLimit. Depending on you are using web3js or etherjs this code will be different. This is example of another minting function.
FT = await contract.ownerMint(WALLET_ADDRESS,{ gasLimit: 285000, gasPrice: ethers.utils.parseUnits('30', 'gwei')});
Edit2: you can always deploy it with remix online with Metamask

MetaMask RPC error? 'MetaMask - RPC Error: Internal JSON-RPC error.'

I'm developing the front-end to an application that I'm trying to test. However, MetaMask keeps giving me this error? I tried changing the gas limit like previously suggested and nothing. Any ideas?
Error:
MetaMask - RPC Error: Internal JSON-RPC error.
code: -32603
data: {code: -32000, message: "gas required exceeds allowance (30000000) or always failing transaction"}
message: "Internal JSON-RPC error."
Without seeing the code, it's hard to say for sure but you could try:
Check any code you changed in the front end, specifically in your code you may have something like this:
const contractInstance = new state.web3.eth.Contract(
MyContract.abi,
"0x.....", // contract address
{
from: state.accounts[0],
gasPrice: 1000,
gas: 100000
}
);
Make sure the gas prices are similar to those, you may have to adjust for your case.
Re-compile and redeploy --> for truffle, run truffle develop first, then compile then migrate --reset for local deployment.
In Metamask, reset your test account. Metamask > Select Account > Settings > Advanced > Reset account. Only do this for testing accounts
Previously it used to happen in older versions due to a gas specification issue which was fixed. rpcErrors.internal` expects a string as the first argument, with arbitrary data being the optional second argument. Passing in a non-
string first argument results in the error being shadowed by an error
from eth-json-rpc-errors.
Please check what you are passing to Metamask.
In my case, after trying so many options I have restarted Ganache and re-imported new account from Ganache to Metamask.
I connected this new account with localhost application.
This resoles my issue.
Before performing any transaction the sending ETH address must be connected to your own site or UI. So it can get the address of sending account and goes towards the further transaction in the metamask.
Make sure Your sending account address must be connected to your UI.

Issue Deploying Raiden Contracts and Starting Raiden Client on Private Geth Network

I am trying to deploy Raiden smart contracts and start Raiden client on a private GETH network using this tutorial from the Raiden team but it seems to be outdated and I am running into multiple errors, so I am able to deploy all the Raiden contracts with contract-version==0.25.0 successfully on GETH v1.9.21-stable but starting up Raiden client v0.200.0-rc9-macOS-x86_64 I get this error
[UserDeposit] Address 0x246c6c859B0ab7ab970cA2f3764B757c20CD5477 has wrong code. This may happen if Raiden is configured to use an unsupported version of the contracts.
It is the same error when I try with Raiden client v1.x.x. I decided to take another look at deploying Raiden contracts with contract-version==0.37.0 after failing to deploy on GETH v1.10.1-stable, reaching out to the dev team and they suggested using v1.9.21-stable, but I get a vague error. which is hard to debug when deploying the TokenNetworkRegistry.sol
raise ValueError("Status 0 indicates failure")
Printing out web3.eth.getTransactionReceipt(txhash) for TokenNetworkRegistry.sol the status is indeed 0 and it throws an Out of Gas exception. Increasing the gas limit still throws the same exception.

How to check if AWS X-Ray has been configured

We have an AWS Lambda running in Go, and upon initialisation runs the following to initialise AWS X-Ray
err := xray.Configure(xray.Config{
LogLevel: "info",
ServiceVersion: "1.2.3",
})
In a seperate repository, we have a utils repository which exposes a HTTP library for our internal stuff. This is imported as a git submodule to all other Lambdas. The code is as follows:
ctx, subseg := xray.BeginSubsegment(incomingContext, "Outbound HTTP call")
client := xray.Client(&http.Client{Transport: tr})
// further down
client.Do(req)
// finally
subseg.Close(resp)
This works as expected when deployed on AWS, producing a nice graph.
The problem is running unit tests on the utils repository. In the context of that repository alone, X-Ray has not been configured, so on the BeginSubsegment call I get a panic:
panic: failed to begin subsegment named 'Outbound HTTP call': segment cannot be found.
I want to gracefully handle the case when X-Ray has not been configured, log it, and carry on execution regardless.
How can I ensure to properly error handle the call to BeginSubsegment when it does not return an error object?
In the case of lambda this code executes without any panic is because lambda creates a facade segment and then your code will be creating subsegments. In the non lambda environment you will have to create a segment first before creating a subsegment. If you don't then it will generate a panic. Now, If you want to log this panic and continue executing your unit tests then I would recommend you to set AWS_XRAY_CONTEXT_MISSING environment variable to LOG_ERROR. It will basically log your panic and continue executing your unit tests.