我使用web3在两个钱包之间传输令牌。我正在成功地生成和签名事务,正在创建一个散列,但从未更新到网络。我正在使用Rinkeby测试网络。GETH正在显示正在创建的事务。我已经等待了几个小时的交易,其中之一,我已经等待了24小时到目前为止。
在对原始事务数据进行签名并将其转换为十六进制字符串之前,如下所示:
{
from: '0x1A9c7...',
to: '0xaed2df...',
nonce: '0x10',
gasPrice: '0x5208',
gasLimit: '0x670aac',
value: '0x00',
data: '0xa9059cbb0000000000...',
chainId: 4
}下面是我用来生成事务的代码,请注意,web3legacy是0.20.x,web3是1.0.0-beta20
let sendTransaction = async () => {
const senderAddress = "0x1A9c7c...";
const destinationAddress = "0x2aABeb...";
const transferAmount = 100;
const nonce = web3legacy.eth.getTransactionCount(senderAddress);
const rawTransaction = {
from: senderAddress,
to: contractAddress,
nonce: web3legacy.toHex(nonce),
gasPrice: web3legacy.toHex(web3legacy.eth.estimateGas({from: senderAddress, to: destinationAddress, amount: web3legacy.toWei(0, "ether")})),
gasLimit: web3legacy.toHex((await web3.eth.getBlock("latest")).gasLimit),
value: "0x00",
data: contract.transfer.getData(destinationAddress, transferAmount, { from: senderAddress }),
chainId: 4
};
// senderAddress private_key
const privateKeySnapshot = await walletsRef.child(senderAddress).once('value');
const rawPrivateKey = privateKeySnapshot.val();
const privateKey = new Buffer(rawPrivateKey, "hex");
const transaction = new Transaction(rawTransaction);
transaction.sign(privateKey);
console.log("Validation:", transaction.validate());
const serializedTransaction = transaction.serialize();
web3legacy.eth.sendRawTransaction('0x' + serializedTransaction.toString("hex"), (err, hash) => {
if(err) console.error("ERROR:", err);
else {
console.log("HASH:", hash);
}
});
};transaction.validate()的验证是成功的。
散列是从sendRawTransaction方法创建的,但它从未出现在rinkeby网络上,并且我的钱包/令牌从未受到影响。我得到常见的错误消息“对不起,我们无法找到交易哈什”从rinkeby以太扫描。
对于任何好奇的人,sendSignedTransaction in 1.0.0 is currently bugged and doesn't work per issue #1102 which is why I brought in 0.20.0 to send a raw transaction
发布于 2017-12-22 09:21:15
你们的汽油价格太低了。应该是至少20克卫(20000000000)。问题是,你使用的是estimateGas,它告诉你你需要多少汽油,来给出一个汽油价格,这就是你将支付多少乙醚单位的天然气。
类似地,您的gasLimit非常高,但这并不是什么大问题,因为(假设您的调用成功)您将得到退款。您可以在那里使用estimateGas,但是一定要估计您的实际调用,而不是零以太传输。
https://ethereum.stackexchange.com/questions/34134
复制相似问题