Using Hardhat to deploy smart contract to local Polygon node - blockchain

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.

Related

Deploying to fuji network with hardhat creates HttpProviderError

I am having issue deploying contract to fuji c chain with hardhat. Here is my hardhat.config.js file:
const config: HardhatUserConfig = {
networks: {
fuji: {
url: 'https://api.avax-test.network/ext/bc/C/rpc',
chainId: 43113,
gasPrice: 20000000000,
accounts: [`0x${PRIVATE_KEY}`],
},
avalanche: {
url: 'https://api.avax.network/ext/bc/C/rpc',
chainId: 43114,
gasPrice: 20000000000,
accounts: [`0x${PRIVATE_KEY}`],
},
},
};
Here is the command for deploying the contract:
npx hardhat run --network fuji scripts/deploy.ts
I am getting the following error:
ProviderError: HttpProviderError
at HttpProvider.request (E:\SolidityProject\Leveor\nft-platform-script\node_modules\hardhat\src\internal\core\providers\http.ts:78:19)
I also have used a different rpc url provided by infura with the API key but it gave the same error.
How to resolve this?
The problem was setting the gasPrice on the hardhat config file. For the fuji network the gas is automatically calculated and explicitly setting a gas price causes the error ProviderError: HttpProviderError (The error message could be better). This is the same case for the Celo network. But for Ethereum, Polygon, and Binance smart chains you CAN explicitly define the gas price.

How to deploy a smartcontract and make a transfer from it in Everscale blockchain

I found this quickstart guide on how to do it locally. But there is no information about on how I can deploy my smartcontract to devnet or mainnet.
So I changed endpoint:
const client = new TonClient({
network: {
endpoints: ["https://net.ton.dev"]
}
})
According to comment, I removed useGiver:
// Request contract deployment funds form a local TON OS SE giver
// not suitable for other networks.
// Deploy `hello` contract.
await helloAcc.deploy(/*{ useGiver: true }*/);
And got this this error message:
Account does not exist. You need to transfer funds to this account first to have a positive balance and then deploy its code
How do I fund my account, is there any automatic method like airdrop?
We added a couple of guides about how to deploy and configure your own giver in developer network. Please, check them out:
Work with devnet with everdev tool - https://github.com/tonlabs/everdev/blob/main/docs/work_with_devnet.md
Configure giver in AppKit - https://tonlabs.gitbook.io/appkit-js/guides/custom_giver
You need to first calculate the contract address in the target chain and then tip it up to 1 EVER for deployment to succeed.
The amount of gas needed depends on the code of the contract, but cannot exceed 1 EVER.
There are no automatic givers in net.ton.dev now. But you can get rubins from here: faucet.extraton.io Also you can create automatic giver in this test network by yourself.

Running Metaplex on localhost

Trying to run Metaplex with locally hosted test validator. The wallet seems to be connecting correctly and showing the balance as expected. But it fails to initialize the store. Whenever I press "init store" I run into a timeout waiting for the transaction confirmation.
To enable connecting to localhost I've modified ENDPOINTS in 'connection.ts by adding the following to the array:
{
name: 'localnet' as ENV,
endpoint: 'http://127.0.0.1:8899',
ChainId: ChainId.Devnet,
}
Upon a closer investigation it seems that the init store does not actually deploy the programs to the local blockchain.
If by "Metaplex" in your orginal post you are referring to the Web UI here https://github.com/metaplex-foundation/metaplex/tree/master/js/packages/web keep in mind this UI does a lot of stuff.
As you have noted in your update: Metaplex is composed of many different program accounts. You would have to locate each of these accounts then "--clone" them on the solana-test-validator command line in order to ensure Metaplex works.
AFAIK there is no script or instructions about how to set up Metaplex from scratch.
The Metaplex storeFront is deprecated and is no longer maintained by the Metaplex Team. So i will advice for building an NFT Marketplace better use the Auction house contract for that. Here is the link for Auction house link

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

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.