i am using a the latest npm version of web3 and when i try to send a data an error occurs. Transaction failed. if i downgrade my web3 version to 1.2.2 my transaction works successfully.
import Web3 from "web3";
const getWeb3 = () => { return new Promise(async (resolve, reject) => { try { // Modern dapp browsers... if (window.ethereum) { const web3 = new Web3(window.ethereum);
// Request accounts using eth_requestAccounts
await window.ethereum.request({ method: "eth_requestAccounts" });
// Accounts are now exposed
resolve(web3);
}
// Legacy dapp browsers...
else if (window.web3) {
// Use Mist/MetaMask's provider.
const web3 = new Web3(window.web3.currentProvider);
console.log("Injected web3 detected.");
resolve(web3);
}
// Fallback to localhost; use dev console port by default...
else {
const provider = new Web3.providers.HttpProvider(
"http://127.0.0.1:7545"
);
const web3 = new Web3(provider);
console.log("No web3 instance injected, using local web3.");
resolve(web3);
}
} catch (error) {
reject(error);
}});};
export default getWeb3;