const ethers = require('ethers');
async function createBytes (args) {
const name = args[0];
const bytes = ethers.utils.formatBytes32String(name);
console.log('name: ',bytes)
}
createBytes(process.argv.slice(2));

What's wrong in it and i can't understand this error. I am trying to run js file through a powershell
You are using the old v5 syntax.
formatBytes32String has been renamed to encodeBytes32String in v6:
// v5:
bytes32 = ethers.utils.formatBytes32String(text)
text = ethers.utils.parseBytes32String(bytes32)
// v6:
bytes32 = ethers.encodeBytes32String(text)
text = ethers.decodeBytes32String(bytes32)
Change your code to the following:
const ethers = require('ethers');
async function createBytes (args) {
const name = args[0];
const bytes = ethers.encodeBytes32String(name);
console.log('name: ',bytes)
}
createBytes(process.argv.slice(2));
name: 0x736f6d657468696e670000000000000000000000000000000000000000000000
For more info, check the 'Utilities' documentation page
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With