ethers.utils.toUtf8Bytes: str.charCodeAt is not a function
See original GitHub issueDescribe 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:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.@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. 😃