Skip to content

Instantly share code, notes, and snippets.

@earthchie
Last active July 31, 2024 10:44
Show Gist options
  • Select an option

  • Save earthchie/a9e42499cfdb3ef3f5db73cf39c6248d to your computer and use it in GitHub Desktop.

Select an option

Save earthchie/a9e42499cfdb3ef3f5db73cf39c6248d to your computer and use it in GitHub Desktop.
Add text memo to blockchain transaction with ethers.js
const provider = new ethers.providers.JsonRpcProvider('https://data-seed-prebsc-1-s1.binance.org:8545/'); // TESTNET
const privateKey = '0xea0beba96beab7b2b8a79b2142f89c07a51342d6a2ebb0822267096d5b65abf7'; // address: 0x8526aDDf97F478bEb92223383778A4e8688951D9
const wallet = new ethers.Wallet(privateKey, provider);
let balance = await provider.getBalance(wallet.address);
console.log('My Initial Balance is:', ethers.utils.formatEther(balance));
const trx = await wallet.sendTransaction({
to: '0x4Bd3Cea4dbeCb1bE89e690A049Ce7fa533B1d1eE', // private key: 0x002d370dbb49f65b232c69852f1148232bafd5c4427c0cf8ee52a1bbb72fe2f8
value: ethers.utils.parseEther('0'), // send 0 BNB
data: ethers.utils.formatBytes32String('Add Memo Message Here')
});
@juniorcines
Copy link

Hello, I get the following error:

{"code":-32000,"message":"intrinsic gas too low"}}

code: data: ethers.utils.formatBytes32String('Add Memo Message Here')

@juniorcines
Copy link

Hello, I get the following error:

{"code":-32000,"message":"intrinsic gas too low"}}

code: data: ethers.utils.formatBytes32String('Add Memo Message Here')

I already solved it I had to raise the gas.

@earthchie
Copy link
Author

btw, just add a new gist for another approach. If you want to add memo to a contract call, check this: https://gist.github.com/earthchie/1f12cab7f20bb6cef84a9d9fa1be507b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment