- 普通交易
交易数据
let transaction = {
from: ethereum.selectedAddress, // 当前选中账户
to: toAddress,
value: ethers.utils.parseEther(value)._hex,
// chainId: ethers.utils.parseEther('56')._hex
}
发送交易
ethereum.request({ method: 'eth_sendTransaction', params: [transaction] })
- 携带备注
data: ethers.utils.formatBytes32String('hahah') // 文本
// 字符串需要转换为32字节的字节数组(bytes32)才能存储在区块链上。
// Ethers.js库的formatBytes32String函数可以将字符串转换为32字节的字节数组。
data: ethers.utils.hexlify(222) // 16进制数字