I am getting this error:
TypeError: Cannot read property 'sendTransaction' of null
when running this command:
$ npx hardhat run scripts/deploy.js --network ropsten
with HardHat on Ropsten network.
This is my deploy.js (which is the one provided by HardHat):
const hre = require("hardhat");
async function main() {
const Greeter = await hre.ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy("Hello, Hardhat!");
await greeter.deployed();
console.log("Greeter deployed to:", greeter.address);
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
This is my App.js:
import { useState } from 'react';
import { ethers } from 'ethers';
import './App.css';
import Greeter from './artifacts/contracts/Greeter.sol/Greeter.json';
function App() {
const greeterAddress = '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512';
const [greeting, SetGreetingValue] = useState('');
async function requestAccount() {
await window.ethereum.request({
method: 'eth_requestAccounts',
});
}
async function fetchGreeting() {
if (typeof window.ethereum !== 'undefined') {
const provider = new ethers.providers.Web3Provider(window.ethereum);
const contract = new ethers.Contract(greeterAddress, Greeter.abi, provider);
try {
const data = await contract.greet();
console.log('data: ', data);
} catch (error) {
console.error(error);
}
}
}
async function setGreeting() {
if (!greeting) return;
if (typeof window.ethereum !== 'undefined') {
await requestAccount();
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const contract = new ethers.Contract(greeterAddress, Greeter.abi, signer);
const transaction = await contract.setGreeting(greeting);
SetGreetingValue('')
await transaction.wait();
fetchGreeting();
}
}
return (
<div className="App">
<button onClick={fetchGreeting}>Fetch Greeting</button>
<button onClick={setGreeting}>Set Greeting</button>
<input placeholder='Set greeting' onChange={(e) => SetGreetingValue(e.target.value)} placeholder='Set Greeting' value={greeting}/>
</div>
);
}
export default App;
And this is the hardhat.config.js:
module.exports = {
solidity: "0.8.4",
paths: {
artifacts: './client/src/artifacts'
},
networks: {
hardhat: {
chainId: 1337
},
ropsten: {
url: "https://ropsten.infura.io/v3/938ec750ced64edda8fc17c9e135d0f6",
account: [`0x08c75f58dcad3bc9664F2ba9Db3C10b2555D6702`]
}
}
};
I do not understan why I am getting this sendTransaction error when there is no sendTransaction anywhere in the code