question-mark

Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot invoke contract functions

See original GitHub issue

Issue Description

Hello, I am new to starknet js. I’m trying to invoke a function of a contract using this code :

        const { transaction_hash: transferTxHash } = await account.execute(
            {
                contractAddress: eykarCommunityContract.address,
                entrypoint: "completeQuest",
                calldata: [questId, player],
            },
            undefined,
            { maxFee: "0" }
        );

But I get this error:

TypeError: Cannot read properties of undefined (reading '0')
    at Account.<anonymous> (/home/nicolas/Desktop/Nico/eykar/API/node_modules/starknet/dist/account/default.js:125:92)

So I went to /home/nicolas/Desktop/Nico/eykar/API/node_modules/starknet/dist/account/default.js:125:92

the error is here:

    Account.prototype.getNonce = function () {
        return __awaiter(this, void 0, void 0, function () {
            var result;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.callContract({
                            contractAddress: this.address,
                            entrypoint: 'get_nonce',
                        })];
                    case 1:
                        result = (_a.sent()).result;

                        // ------------------------------------------I Added a console.log -----------------------------------------
                        console.log(_a.sent())


                        return [2 /*return*/, (0, number_1.toHex)((0, number_1.toBN)(result[/*     THIS IS THE ERROR        */0]))];
                }
            });
        });
    };

So I printed the source of the “result” variable in the console (_a.sent()), and I get this:

[Object: null prototype] {
  code: 'StarkErrorCode.MALFORMED_REQUEST',
  message: "can't use a string pattern on a bytes-like object"
}

So there’s definitely something I missed (this is the first time I’ve done this). If you have an idea of the problem, don’t hesitate. Thank you in advance

Issue Analytics

  • State:closed
  • Created 6 months ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Marchand-Nicolascommented, Jul 14, 2022

I solved the problem by changing my account. I used an account generated on ArgentX. (and the .toLowerCase() helped me with the address given by ArgentX)

1reaction
0x25cfb68commented, Jul 13, 2022

I just faced this issue too, like you did I was able to track it down to getNonce (link)

I noticed that this call fails if the address has capital letters (checksumed):

const { result } = await this.callContract({
  contractAddress: this.address,
  entrypoint: 'get_nonce',
});

looks like Starknet fails to make calls to contracts with checksumed address, the weird thing is that executing calls works without needing to lowercase the address 🤔

when I updated my account initialization it worked

const account = new Account(
   defaultProvider,
   process.env[`ACCOUNT_ADDRESS`].toLowerCase(),
   ec.getKeyPair(import.meta.env[`ACCOUNT_PRIVATE_KEY`])
);

PS: I copied the address straight from Argent wallet without noticing it was checksumed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot invoke contract function from console using truffle
In the contract the function is called getHelloMessage , but you are calling getHelloWorld . You should type in the console
Read more >
Cannot call function within deployed contract - Stack Overflow
Yes it is a function, defined in my contract, though console.log(contract.displayMessage) will return the object posted above. If I run console.
Read more >
Unable to call other contract function · Issue #19752 - GitHub
It should allow calling other contract function using low-level call. Actual behaviour. It doesn't allow to call other contract function. My ...
Read more >
Interact with your contracts - Truffle Suite
When you execute a contract's function via a transaction, you cannot receive that function's return value because the transaction isn't processed ...
Read more >
How to call another smart contract from your solidity code
1. Smart contracts are the most popular feature of the Ethereum network. Smart contracts have functions ... 2. Smart contracts are computer code,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found