Use the React SDK to interact with smart contracts deployed to a local Hardhat node.
The code is split into two directories:
contracts
: Contains the smart contracts and the scripts to deploy to a local node.application
: Contains the React application that interacts with the smart contracts.
Clone this repository using the CLI.
npx thirdweb create --template hardhat-local-node
Install the dependencies for the project, in both the contracts
and application
directories.
cd application
npm install
cd ../contracts
npm install
Use the hardhat
CLI to run a local node.
# From within the /contracts directory
npx hardhat node
Use the CLI to deploy the smart contracts to the local node via the dashboard.
# From within the /contracts directory
npx thirdweb deploy
This command compiles your contract and produces a link to the dashboard where you can deploy the contract to a local node.
Use the Request testnet funds
button to load your wallet with some funds to deploy the contract.
Ensure to select the Localhost (ETH)
network and click on the Deploy
button!
Once deployed, copy your contract address from the dashboard:
Paste it in the application/pages/index.tsx
file, within the useContract
hook.
const Home: NextPage = () => {
const { contract, isLoading, error } = useContract(
// Your contract address here!
"0x..."
);
};
export default Home;
For any questions, suggestions, join our discord at https://discord.gg/thirdweb.