[英]Uncaught (in promise) Error while opening and doing transaction on private ethereum blockchain using web3 and go-ethereum
[英]How to set the transaction hash with useState in an Ethereum transaction
我想用 React 鈎子設置一個變量。 每當我發送以太坊交易時,都可以通過 on('transactionHash', {...}) 方法獲取它的哈希值,但是如果我嘗試調用 setTransactionHash 則沒有任何反應。 這是代碼:
import React, {useState, useEffect, useCallback} from 'react';
import collegamentoConDb from '../api/collegamentocondb';
const Admin = ()=>{
const [transactionHash, setTransactionHash] = useState("");
...
try{
window.ethereum.enable();
const accounts = await web3.eth.getAccounts();
await contract.methods.notarizzazione(hashCampi).send({
from:accounts[0]
}).on('transactionHash', (hash)=>{
setTransactionHash(hash)
});
} catch(err){
console.log(err);
}
//db call
const fileTestoPdf = await collegamentoConDb.post('/creapdf', {id, transactionHash});
...
當我閱讀日志文件時,transactionHash 沒有更新,我不明白為什么。 有人能幫我嗎?
謝謝你。
你能在控制台中得到哈希嗎? 如果是,則嘗試const [transactionHash, setTransactionHash] = useState();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.