node.js - Error: Only replay-protected (EIP-155) transactions allowed over RPC
问题描述
When I try to send funds from a token address to another I encounter this error: only replay-protected (EIP-155) transactions allowed over RPC
My Code:
const contract = new web3.eth.Contract(ABI,token_contract_address);
const data = contract.methods.transfer(to, req.body.value).encodeABI();
const rawTransaction = {
'from': from,
'nonce': web3.utils.toHex(web3.eth.getTransactionCount(from)),
'gasPrice': web3.utils.toHex(web3.eth.gasPrice),
'gasLimit': web3.utils.toHex(21000),
'to': token_contract_address,
'value': 0,
'data': data,
'chainId': web3.utils.toHex(chainid)
};
const privateKey = new Buffer.from(req.body.PrivateKey, 'hex');
const tx = new Tx(rawTransaction);
tx.sign(privateKey);
const serializedTx = tx.serialize();
web3.eth.sendSignedTransaction(('0x' + serializedTx.toString('hex')),req.body.PrivateKey)
.then(function (result) {
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
res.json(result*decimals);
console.log(result);
})
.catch((err) => next(err));
Notice I have already added ChainId
解决方案
推荐阅读
- git - 如何在特定日期后获取所有提交 ID 并仅显示已更改的文件?
- postgresql - Docker-Compose up Failed 因为`Service 'nginx' failed to build`
- python - 如何计算交货日期后 8 个月后的日期?
- rust - 将借用值的向量收集到借用特征的向量中
- javascript - 在获取 Spring Rest Controller 的 fetch post 请求时收到 404?
- google-apps-script - 当列与今天日期匹配时,记录一个单元格并将数据复制到同一行中的单元格
- javascript - 为什么我的 bcrypt.compare() 函数返回 false?
- markdown - 如何让 Prettier 忽略换行符的降价注释
- android - Android 和 Instagram 辅助功能事件问题
- javascript - 使用箭头键滚动在 Gatsby 中不起作用