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.

ethers.utils.toUtf8Bytes: str.charCodeAt is not a function

See original GitHub issue

Describe the bug

Using code like

ethers.utils.toUtf8Bytes('test');

will result in a TypeError:

TypeError: str.charCodeAt is not a function at toUtf8Bytes

Reproduction steps

yarn install ethersjs // latest “ethers”: “^5.5.2”

const {ethers} = require("hardhat");
console.log(ethers.utils.toUtf8Bytes('test'));

Environment:

node: v16.13.1 hardhat ^2.7.1 ethers: 5.5.2

Search Terms

TypeError, toUtf8Bytes, charCodeAt

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
seeARMScommented, Jan 21, 2022

Leaving this here for any future Googlers:

I was also encountering this issue. I was passing an array of strings to a smart contract write call, and hitting the exception ‘str.charCodeAt is not a function’. It turns out I was using the wrong smart contract name - I was using one that expected just a string, and not an array.

3reactions
ricmoocommented, Mar 26, 2022

@mayuranganesathas I think that’s your best bet; the stacktrace is powerful. Make sure you use a non-minified version to keep your headaches to a minimum. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error when executing function using Ethers : r/ethdev - Reddit
Every other contract function works, but I receive "Uncaught (in promise) TypeError: str.charCodeAt is not a function" error message when I ...
Read more >
Getting Error as str.charCodeAt is not a function - Stack Overflow
I found the problem in the Msg91 npm package, I created a pull request for the author to merge it. Here is the...
Read more >
String to Hex in Ethers.js - Ethereum Stack Exchange
I couldn't find such a function in ethers.js ( hexlify doesn't accept ... hexString = utf8ToHex(string); const web3HexString = web3.utils.
Read more >
System error :“this.str.charCodeAt is not a function” - General
I'm using Firefox for my Metamask and it works just fine. Before I used Chrome and often had some problems with it. Maybe...
Read more >
Strings - Ethers.js
ethers.utils. ... toUtf8Bytes( text [ , form = current ] ) ⇒ Uint8Array ... The onError is a Custom UTF-8 Error function and...
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