How to create and use 1k wallet signers on hardhat to test smart contracts? - solidity

I am gonna write smart contracts test on hardhat.
By default, hardhat provides 20 signers with enough amount of ETH on it.
But for my contracts, I will need 1000 signers and each signer should have some eth on it.
How can I achieve this? I can create any amount of random wallets using ethers but am not sure how to send ether and use that random wallet.

In hardhat.config.js[ts], you could config accounts.
Like this:
module.exports = {
...
networks: {
hardhat: {
accounts: [
privateKey0,
privateKey1,
privateKey2,
...
]
}
}
...
}
how to send ether:
https://ethereum.org/en/developers/tutorials/send-token-etherjs/

Related

Provider Error : Provider : Transaction Reverted without Reason String

We have been working on Document Signing App which sends an email when a user uploads a document and sends it to sign to another 3-4 users.
The user gets the email and tries to sign the document which does a blockchain transaction whose status is always failed.
We have been trying to debug this but unfortunately we haven’t any details lately, We have tried various codes but no changes have changed the status of transaction.
Our System Details :
Provider : Alchemy
Network : Goerli / Localhost ( Hardhat node )
Local Dev : Hardhat
We also tried to use hardhat console.sol but we could not get any logs in the contract when using Hardhat node, No logs were printed using npx hardhat test.
We have been facing this problem since almost a week now and the transaction is stil failing.
Snapshot of Local Error :
ProviderError: Error: Transaction reverted without a reason string
at HttpProvider.request (node_modules/hardhat/src/internal/core/providers/http.ts:78:19)
at GanacheGasMultiplierProvider.request (node_modules/hardhat/src/internal/core/providers/gas-providers.ts:312:34)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Smart Contract that is failing in actual transaction :
function sign(bytes32 hash, bytes32 signatureHash, address signer) public {
console.log("Entered Sign Function");
require(checkDoc(hash),"check doc failed");
require(documents[hash].signers[signer] == 1, "signer failed");
documents[hash].remainingSignatures--;
documents[hash].signers[signer] = block.timestamp;
emit Signature(hash, signatureHash, signer, 'Signature');
if (documents[hash].remainingSignatures == 0){
documents[hash].status = currentState.signed;
emit Signed(hash, 'Signed');
}
Require is not the issue because when we comment out require statements the transaction is still failing.
Code for Test case that is failing :
it("Signing contract", async function () {
const DocumentSigning = await ethers.getContractFactory("DocumentSigning");
const document_signing = await DocumentSigning.deploy();
const transactionOptions = {
gasLimit: 2500000
}
await document_signing.sign("0x46742b637a5c1d01460033c3bd178d1fafe78e0dffa5d2d1841dcccaf70d30a9", "0xef02795fa1b0c97abe843fb461b4625a6a24662bff227862d7d292c9fc69c1ab", "0x07906aae1204f6f3b81673562db7776af9acf83c", transactionOptions);
});
});
The values for test cases have been hardcoded for now to test the actual transaction flow.
Can some help on this as soon as possible?
Adding link to a sample transaction that failed :
https://goerli.etherscan.io/tx/0x4c1665f793541846457a27467236d5fccca63588be3064c78682f666393adc74

Verifying Smart Contract programmatically using POST method for APIs returning this error: "Error! Missing Or invalid Module name"

I'm trying to verify a simple contract programmatically on BSCScan testnet using their APIs as they have explained in their docs: verifying-contracts-programmatically.
I don't intend to use Hardhat or a similar tool.
I am doing this on a REACT APP.
I am using AXIOS in my app to handle the POST method explained by Etherscan in their docs: Source Code Verification Procedure by Etherscan.io.
Here's my post method code:
(values I have left blank are those that the docs have suggested can be left blank for default settings)
axios.post("https://api-testnet.bscscan.com/api", {
apikey: ">>MY API KEY<<", // I have retracted my API key here
module: "contract", //Do not change
action: 'verifysourcecode',
contractaddress: '0xF3A6da5375C795bbc9606a50b1246EA0a7921bEE',
sourceCode: "// SPDX-License-Identifier: MIT \npragma solidity ^0.5.0; \n\ncontract Test5 {\n\n}",
codeformat: 'solidity-single-file',
contractname:'Test5',
compilerversion: 'v0.5.5+commit.47a71e8f',
optimizationUsed: 1,
runs: 200,
constructorArguements: '',
evmversion: 'default',
licenceType: 3
})
.then((res) => {
console.log(res);
})
I am however getting this error:
{
"status": "0",
"message": "NOTOK",
"result": "Error! Missing Or invalid Module name"
}
I am still getting the same error even upon using POSTMAN.
Here's my postman bulk edit data:
apikey:>>MY API KEY<<
module:contract
action:verifysourcecode
contractaddress:0xF3A6da5375C795bbc9606a50b1246EA0a7921bEE
sourceCode:// SPDX-License-Identifier: MIT↵ pragma solidity ^0.5.0;↵↵ contract Test5 {↵ ↵ }
codeformat:solidity-single-file
contractname:Test5
compilerversion:v0.5.5+commit.47a71e8f
optimizationUsed:1
runs:200
constructorArguements:
evmversion:
licenceType:3
Anyone knows where I could be doing it wrong? Any help or ideas are highly appreciated.
I had the same problem with other testnet and solved it: Just use "http" instead of "https".

WalletConnect disable infura error message

I am currently developing a dapp and I am integrating walletconnect.
I use this code for connecting:
const chainId = ContractService.getPreferredChainId();
const rpc = ContractService.getRpcAddress();
provider = new WalletConnectProvider({
infuraId: undefined,
rpc: {
[chainId]: rpc,
},
});
await provider.enable();
chainId is dynamically chosen based on if the app is in development mode or not. while in development it runs on chain id 97.
RPC is the same story, it just gets the binance smart chain RPC JSON provider.
Connecting works well, but I get the following error:
Any idea on how I can fix this without making an infura account? Or is that required..
I found out what the problem was.
make sure to add a chainId to the object like this:
new WalletConnectProvider({
infuraId: undefined,
rpc: {
1: "https://RPC_URL",
},
chainId: 1
});
Then it should work without issues, you can even omit the infuraId field

Best way to configure truffle `from` address

I'm setting up my truffle config file and I'm setting the from address from an env variable like this:
module.exports = {
networks: {
local: {
host: "127.0.0.1",
port: 8545,
network_id: "*",
from: process.env.OWNER,
}
}
};
Then I run OWNER=<address> truffle migrate --network local
Any suggestions on a better way to do this, to get truffle to use the first address generated by ganache?
If you omit the from parameter in your truffle.cfg, it will automatically default to the first account returned by web3.eth.getAccounts from the provider you're connected to.
If you want more dynamic control over the account used, you can control this with the deployer.
var SimpleContract = artifacts.require("SimpleContract");
module.exports = function(deployer, network, accounts) {
deployer.deploy(SimpleContract, { from: accounts[1] }); // Deploy contract from the 2nd account in the list
deployer.deploy(SimpleContract, { from: accounts[2] }); // Deploy the same contract again (different address) from the 3rd account.
};
Of course, you don't have to use the account list passed in and you can pull in a list from any other data source you want. You can also use network if you want to have environment specific logic.

who is the owner of the contracts deployed using truffle?

I am using testrpc and truffle to test my contract.
When I type truffle migrate , this will deploy my contract to the testrpc network.
My question is , which account (from testrpc accounts) has been used to deploy the contract.
In other word, whose the contract owner?
Thank you in advance
By default the owner is accounts[0] so the first account on the list but you can set the owner by adding "from" in the truffle.js config file
module.exports = {
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*",
from: "0xda9b1a939350dc7198165ff84c43ce77a723ef73"
}
}
};
for more information about migration see this
https://github.com/trufflesuite/truffle/issues/138