Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error interacting with contract: TypeError: Cannot read properties of undefined (reading 'publicKey') #5

Open
PranavBawgikar opened this issue Feb 6, 2024 · 0 comments
Labels
Bug A error that causes the feature to behave differently than what was expected based on design docs

Comments

@PranavBawgikar
Copy link

Description

hey,

i've been trying to deploy my smart contract on the hedera testnet account (ECDSA), followed all the steps mentioned in the readme.md file, all the environment variables have been set as mentioned but i still keep encountering this error.

when i run npx hardhat test the tests pass, but when i try to interact with the contract again gives me this error:

Issue

node uploadToHedera.js
OK till here Error interacting with contract: TypeError: Cannot read properties of undefined (reading 'publicKey') at NodeClient.setOperator (C:\Users\bawgi\OneDrive\Documents\DEHRSys\dehrsys\node_modules\@hashgraph\sdk\lib\client\Client.cjs:286:48) at interactWithContract (C:\Users\bawgi\OneDrive\Documents\DEHRSys\dehrsys\uploadToHedera.js:28:16) at Object.<anonymous> (C:\Users\bawgi\OneDrive\Documents\DEHRSys\dehrsys\uploadToHedera.js:44:1) at Module._compile (node:internal/modules/cjs/loader:1105:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) at node:internal/main/run_main_module:17:47

i believe the issue is occurring in the \node_modules\@hashgraph\sdk\lib\client\Client.cjs:286:48 file.

the code that is triggering the error:

const { Client, ContractCallQuery } = require("@hashgraph/sdk");

var contractAddress = "0x5c755dDFFBD0B6405DE612Bc96609d21C129917c";

async function interactWithContract(moralisHash) {
    try {
        const client = Client.forTestnet();
        console.log("OK till here")
        client.setOperator(process.env.ACCOUNT_ID, process.env.TESTNET_OPERATOR_PRIVATE_KEY);

        const contract = await new ContractCallQuery()
            .setContractId(contractAddress)
            .setGas(30000)
            .setFunction("changeHash")
            .addString(moralisHash)
            .execute(client);

        console.log("Transaction ID:", contract.transactionId);
    } catch (error) {
        console.error("Error interacting with contract:", error);
    }
}

const moralisHash = "https://ipfs.moralis.io:2053/ipfs/QmQvASqTFsJxNqym55KTm98FVWxwCD9cKt37ba6kYT962z/trainmedications.json";
interactWithContract(moralisHash);

Environment

  • @hashgraph/hedera-local: v2.18.0
  • @nomicfoundation/hardhat-toolbox: v2.0.1
  • dotenv: v16.3.1
  • fs: v0.0.1-security
  • moralis: v2.23.2

Steps to reproduce

node index.js to obtain the hash by Moralis Web3 to store in the uploadToHedera.js file.
npx hardhat compile
npx hardhat deploy-contract
npx hardhat test
node uploadToHedera.js

Additional context

No response

Hedera network

testnet

Version

Hardhat: v2.12.6

Operating system

Windows

@PranavBawgikar PranavBawgikar added the Bug A error that causes the feature to behave differently than what was expected based on design docs label Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A error that causes the feature to behave differently than what was expected based on design docs
Projects
None yet
Development

No branches or pull requests

1 participant