Created
February 23, 2024 21:24
-
-
Save bthaile/6519fe81b278357d9907ed691384b1da to your computer and use it in GitHub Desktop.
GetGreeting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Import ethers from the ethers.js library | |
const { ethers } = require('ethers'); | |
// Define the contract ABI | |
const contractABI = [ | |
"function hello() public view returns (string memory)" | |
]; | |
// Define the contract address | |
const contractAddress = "0x3e6559ef912754b7cb75eaf7f265bdedebb6a437"; | |
// Connect to the Ethereum network | |
// This example uses the default provider from ethers.js, which connects to the Ethereum mainnet. | |
// For a testnet or custom RPC, use ethers.getDefaultProvider('networkName') or new ethers.providers.JsonRpcProvider(url) | |
const provider = new ethers.providers.Web3Provider(window?.ethereum); | |
// Create a new contract instance | |
const contract = new ethers.Contract(contractAddress, contractABI, provider); | |
// Call the hello function of the contract | |
async function getGreeting() { | |
const greeting = await contract.hello(); | |
console.log(greeting); | |
} | |
// Execute the function | |
getGreeting(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment