Ich möchte die Blocknummer basierend auf dem Transaktionshash vom Filter erhalten, aber wenn ich die folgenden Codes zu meinem Projekt hinzufüge, fand ich es seltsam, weil es das Geld manchmal automatisch zweimal überweist und manchmal muss ich ein zweites Mal überweisen, um sehen Sie, wie es den Transaktionshash zurückgibt.
Außerdem bekomme ich die Blocknummer nicht zurück in den Filter. Was ist falsch ?
function TransferTest() {
alert("START TO TRANSFER")
var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
var abiArray=[
{"constant":true,"inputs":[],"name":"minter","outputs":
[{"name":"","type":"address"}],"payable":false,"type":"function"},
{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balances","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},
{"constant":false,"inputs":[{"name":"receiver","type":"address"},{"name":"amount","type":"uint256"}],"name":"mint","outputs":[],"payable":false,"type":"function"},
{"constant":false,"inputs":[{"name":"receiver","type":"address"},{"name":"amount","type":"uint256"}],"name":"send","outputs":[],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"from","type":"address"},{"indexed":false,"name":"to","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"Sent","type":"event"}
];
var object=web3.eth.getTransactionReceipt("0x327fa3ecb7f9312119201995714c6c94a92accfa1643810b2bd3ee6c4f3a038e");
var conAddress=object.contractAddress;
var Mycontract=web3.eth.contract(abiArray);
var MyConIns=Mycontract.at(conAddress);
var uAddress=document.getElementById("uAddress").value;
var tarAddress=document.getElementById("tarAddress").value;
var AKamount=document.getElementById("AKamount").value;
var success=web3.personal.unlockAccount(uAddress,"carochan123");
alert(success);
MyConIns.send(tarAddress,AKamount,{from:uAddress});var filter=web3.eth.filter("pending");
filter.watch(function(error, result){
if (!error)
alert("monitor");
alert(result);
var block = web3.eth.getBlock(result, true);
alert(block.number);
});
alert(MyConIns.balances(tarAddress));//50,150,170,260,270,300,320,330,360,370,380,390,410,420
alert(MyConIns.balances(uAddress));
}
Teilantwort: Es kann sein, dass Sie keine Sperrnummer erhalten können
var block = web3.eth.getBlock(result, true);
alert(block.number);
weil der Block "pending" ist, in diesem Fall number
wird er es seinnull
(siehe web3.eth.getBlock
Rückgabewertbeschreibung).
Erstens, um zu vermeiden, dass Sie Ihre Transaktion verpassen, ist es besser, Ihre Filterüberwachung zu initiieren, bevor Sie die Transaktion ausführen.
Außerdem getBlock()
möchten Sie es möglicherweise asynchron machen, um sicherzustellen, dass ein Wert zurückgegeben wird.
Hoffe das hilft.
Noel Maersk
alert()
? Ist das das richtige Kontopasswort?