【发布时间】:2021-06-13 16:09:05
【问题描述】:
我有一个使用 Wallet 发送 ERC20 交易的网络应用程序(合约交互 -> 转账)。我正在使用 Metamask(主网)与 Web 应用程序进行交互。对于登录(连接),我在 Metamask 中得到确认对话框,对于第一笔交易也是如此。但是,从第二笔交易开始,我没有收到确认对话框。有谁知道可能是什么问题?
我有一个使用 Wallet 发送 ERC20 交易的网络应用程序(合约交互 -> 转账)。我正在使用 Metamask(主网)与 Web 应用程序进行交互。对于登录(连接),我在 Metamask 中得到确认对话框,对于第一笔交易也是如此。但是,从第二笔交易开始,我没有收到确认对话框。有谁知道可能是什么问题?
// SESSION INIT
const providerOptions = {
walletconnect: {
package: WalletConnectProvider,
options: {
infuraId: INFURA_ID,
}
},
};
web3Modal = new Web3Modal({
cacheProvider: true, // optional
providerOptions, // required
disableInjectedProvider: false, // optional. For MetaMask / Brave / Opera.
});
console.log("Web3Modal instance is", web3Modal);
try {
provider = await web3Modal.connect();
} catch(e) {
console.log("Could not get a wallet connection", e);
return;
}
//SEND TRANSACTION
async function transferMoney(toAccountId, amount, tokenContract) {
var data = tokenContract.methods.transferByAccountId(toAccountId, amount).encodeABI()
console.log(data)
var gasPrice = await web3.eth.getGasPrice()
const tx = {
from: selectedAccount,
to: tokenContract.options.address,
gas: TRANSFER_GAS_ESTIMATION,
gasPrice: gasPrice,
data: data,
};
try {
console.log(tx)
var txHash = await provider.connector.sendTransaction(tx)
console.log(txHash)
} catch (err) {
console.log(err.message);
}
}
// DISCONNECT SESSION
async function onDisconnect() {
console.log("Killing the wallet connection", provider);
if(provider.close) {
await provider.close();
await web3Modal.clearCachedProvider();
provider = null;
}
selectedAccount = null;
location.href = 'login.html'
}
【问题讨论】: