Угу*_*ски 8 javascript ethereum metamask
在javascript中我运行契约的方法
contract[methodName](...params, { from: myAccount }, (err, response) => {
console.log('get transaction', methodName, err, response);
if (err) return reject(err);
resolve(response);
});
Run Code Online (Sandbox Code Playgroud)
然后通过MetaMask拒绝交易.在控制台中出错
MetaMask - RPC Error: Error: MetaMask Tx Signature: User denied transaction signature.
Run Code Online (Sandbox Code Playgroud)
但我无法在我的代码中发现此错误.回调不起作用.
我怎样才能在JS中发现这个错误?
如果您使用 Ethers 库,请执行此操作:
contract.methodName(...params, { from: myAccount })
.then(tx => {
//do whatever you want with tx
})
.catch(e => {
if (e.code === 4001){
//user rejected the transaction
}
});
Run Code Online (Sandbox Code Playgroud)