![](/img/trans.png)
[英]How to know the cryptocurrency used in a transaction through the transaction hash?
[英]How to get transaction hash of a transaction with web3ja
我无法获得交易的交易记录我的代码如下请帮助我
这是我使用的脚本标签
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" crossorigin="anonymous></script>
<script>
$(document).ready(function(){
if(window.ethereum) {
ethereum.request({ method: "eth_requestAccounts" });
} else {
console.error("Install Wallet");
}
});
$('#deposit').click(function(){
var amt = 0;
amt = parseInt($('#deposit').val()*1000000000000000000);
const web3 = new Web3(window.ethereum);
web3.eth.sendTransaction({
from: "0x0f63128d7274B30C8e30f884DA6469FF3dF2f8d9",
to: "0x14DC4828b521cF4692Df0CBd4397857Fa267a2B0",
value: amt
}).then(function(err, tx) {
if (err) {
console.log(err);
} else {
console.log(tx);
document.getElementById("txnStt").innerHTML = tx.status;
}
});
});
</script>
web3.js sendTransaction 函数的文档指定了构造承诺处理程序,如下所示:
web3.eth.sendTransaction({
from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe',
to: '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe',
value: '1000000000000000'
})
.then(function(receipt){
...
});
请注意,只有一个参数传递给它,而不是err
和tx
。 让我知道这是否有帮助。
请注意,您可以使用
sendTransaction
函数之外的各种基于事件的处理程序,这些处理程序也可以帮助您进行调试。 见: https ://web3js.readthedocs.io/en/v1.2.11/callbacks-promises-events.html#promievent
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.