I create Front End Web Page For Ether Smart Contract. I before Used Web3 Library And Meta Mask. Now My Web Page is Work. But When I Upload Site On Host For Using Others, When I Test My Web Page In Other Systems And Other Browsers That Don't Used/Installed Meta Mask Extensions, I'm Getting An Error.
Please Some One Help Me How Do I Connect A Web Page To A Contract?
I Before Used This Code For Connecting :
<script >
if (typeof window.ethereum !== 'undefined')
{
console.log('MetaMask is installed!');
}else{
console.log('MetaMask not installed!');
alert("Please install Metamsk wallet first, then try again");
}
const accounts = ethereum.request({ method: 'eth_requestAccounts' });
const account = accounts[0];
const showAccount = document.querySelector('.showAccount');
var contract;
const accounts = ethereum.request({ method: 'eth_requestAccounts' });
const account = accountsH[0];
const showAccount = document.querySelector('.showAccount');
web3 = new Web3(web3.currentProvider);
var address = "0x6246.../* My Contract Address */...5E7a";
var abi =[/* My ABI */];
contract = new web3.eth.Contract(abi, address);
</script>
And It Work. But In Other Browsers That Meta Mask Is Inactive Or Not Installed, I See Error.
I Use Html And Java Scripts For Front End Programming.
I found the answers to my questions.
I have to use infura
check this page
and at first create project at site. and get ID
use this code
web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/v3/3c6/*Your Own ID*/01753"));
Related
Metamask Confirm button not working, couldn't confirm transaction for a smart contract.
I use JS and WalletConnectProvider (website project). Connecting to Metamask by WalletConnect, then call transfer function for custom token contract. I use the same code on desktop and it works and transferring token. Exactly the same code doesn't work on mobile (for Metamask Mobile app). Checked IOS and also Android - the same issue.
Please tell me what is wrong with my code:
<script src="https://cdn.jsdelivr.net/npm/#walletconnect/web3-provider#1.8.0/dist/umd/index.min.js"></script>
<script src="https://[mywebsitescriptspath]/web3.min.js"></script> // 1.8.0
<script type="text/javascript">
var contract
var accountFrom
const ABI = "... abi here....."
var provider = new WalletConnectProvider.default({
infuraId: 'my infura id',
rpc: {
1: "https://mainnet.infura.io/v3/[myinfuraid]",
56: "https://bsc-dataseed.binance.org/"
},
})
const contractAddress = '0xcontraddresshere'
const receiver = '0xreceiveraddresshere'
var connect = async () => {
await provider.enable()
var web3 = new Web3(provider)
web3.givenProvider = web3.currentProvider
web3.eth.givenProvider = web3.currentProvider
web3.eth.accounts.givenProvider = web3.currentProvider
window.w3 = web3
contract = new w3.eth.Contract(ABI, contractAddress)
await w3.eth.getAccounts().then(accounts => {
accountFrom = accounts[0]
})
}
connect()
// function called after the button click
var sendtransaction = async () => {
let vall = 100
let calcAmount = w3.utils.toWei(vall.toString())
let transfer = await contract.methods.transfer(receiver, calcAmount);
await transfer.send({from: accountFrom})
.on('transactionHash', function(hash){
console.log(hash)
})
}
</script>
I tried many different things but it doesn't work.
Tested on wifi, on 4g, on different mobile browsers, on different smartphones (android and IOS).
no success.
The problem started from 5.9.0 Metamask app version.
UPDATE:
Now at 5.10.0 version it doesn't recognize custom contract token. For example when I want to transfer 1 token, it shows 1 BNB.
Last version was better :))
There are open issues on github:
https://github.com/MetaMask/metamask-mobile/issues/5193
https://github.com/MetaMask/metamask-mobile/issues/5235
https://github.com/MetaMask/metamask-mobile/issues/5260
No solution till now - after 14 days.
Change version metamask, working me version - 5.7.0
This issue was solved with the Metamask 5.11.0 updated for IOS 16.1.1. Update your Metamask app to 5.11.0.
Reference: https://github.com/MetaMask/metamask-mobile/issues/5260
Yes, actually they didn't resolve the issue.
In my case, different ERC20 tokens have different result.
On this token, the blue confirm button doesn't work.
https://etherscan.io/token/0x377e0c5d3738FAcd2D4c1CA192c774e978E8e95b#writeContract
But on USDC (0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48)
It works well.
iOS ver 16.1.2
MetaMask v5.12.0
Currently, I need to use proxy with authentication, on selenium-webdriver on Firefox.
I successfully connect to Tor using :
var option = new Options();
option.headless()
option.setPreference('network.proxy.type', 1)
.setPreference('network.proxy.socks', '127.0.0.1')
.setPreference('network.proxy.socks_port', 9050)
.setPreference('network.proxy.socks_remote_dns', true)
.setPreference('network.proxy.socks_version', 5)
let driver = await new Builder()
.forBrowser(Browser.FIREFOX)
.setFirefoxOptions(option)
.build();
But I don't find how to pass username and password for other proxy.
I looked on Selenium's github, but nothing worked. This is the exemple on the file's comment but not working:
let capabilities = new Capabilities();
capabilities.setProxy(proxy.socks('username:pass#host:port'))
// for tor
capabilities.setProxy(proxy.socks('host:port'))
let driver = await new Builder()
.withCapabilities(capabilities)
.forBrowser(Browser.FIREFOX)
.setFirefoxOptions(option)
.build();
Please help me :(
You could try using the following with setPreference itself:
.set_preference("network.proxy.socks_username", USERNAME)
.set_preference("network.proxy.socks_password", PASSWORD)
I am trying Metamask connect on mobile Metamask application. But i am not getting properly solutions for that. It's working fine in Web browser Metamask Extension.
The following code used for Web browser in Magento 2. But, not working with Mobile application. I am trying also using detectEthereumProvider. But, it's also not working with mobile Metamask. I had also used Provide window ethereum. But, it's also not working.
require([
'jquery',
'Magento_Theme/js/view/messages',
'mage/url',
'web3'
], function($,messages,url,web3){
let accounts;
let contract;
let contractAddress;
const getData = async () => {
var web3 = new Web3(window.ethereum); /* initialize web3 object */
const { ethereum } = window;
var web3 = new Web3(window.ethereum);
if (typeof window.ethereum !== 'undefined') {
console.log('MetaMask is installed!');
}
}
getData();
}
);
I am also using vanilla js using wallet connect with Web3model but also not working. Because, It's said Web3Modal NPM Package must be use for Web3model but it's possible on magento 2?
I am setting up the first automated tests for a web app I'm working on, and have hit a state I don't understand.
It is a browser app, so I start a very simple static server:
import http from 'http';
let serve = serveStatic(path);
server = http.createServer(function(req, res) {
var done = finalhandler(req, res);
serve(req, res, done);
});
During my testing, I receive an error message HTTP method not allowed
let options = new firefox.Options();
options.headless();
let capabilities = webdriver.Capabilities.firefox().set('acceptInsecureCerts', true);
let driver = new webdriver.Builder()
.forBrowser('firefox')
.setFirefoxOptions(options)
.withCapabilities(capabilities)
.build();
await driver.get('http://127.0.0.1:3030/index.html');
let tab = await driver.findElement(state.By.css('ps-tabpanel'));
tab = await tab.getShadowRoot(); // HTTP method not allowed
On a hunch, I changed this to an HTTPS connection
import http from 'https';
In this case I receive a very different error
await driver.get('https://127.0.0.1:3030/index.html');
// Reached error page: about:neterror?e=nssFailure2&u=https%3A//127.0.0.1%3A3030/index.html&c=UTF-8&d=%20
So my main question is, what am I doing wrong to access the shadowRoot using Javascript Selenium?
For reference
mocha + selenium + firefox
gitpod environment
have an earlier test that simply verifies I can connect to example.com just to prove the connection is working.
In an attempt to work around the error, I switched to the javascript executor. This raised a different error message (cyclical object).
This led me to a different stackoverflow question
https://stackoverflow.com/a/67223939/1961413
According to that answer, this is a known defect in the GeckoDriver/Firefox.
Based on that I switched to the ChromeDriver/Chrome, and was able to find the ShadowRoot.
https://www.npmjs.com/package/chromedriver
let driver = new webdriver.Builder()
.forBrowser('chrome')
.build();
await driver.get('http://127.0.0.1:3030/index.html');
let tab = await driver.findElement(state.By.css('ps-tabpanel'));
tab = await tab.getShadowRoot();
I am using Dialogflow V2 API.
Everything works perfectly in testing via Actions on Google simulator. Please find pic attached.
However, when attempted using the console (right column) within Dialogflow, and also the web integration link, it does not work.
Agent is able to detect appropriate entity from user input, but unable to call intent declared in webhook.
https://bot.dialogflow.com/acc64a26-8d1d-4459-8ce0-24c890acb6d7
I have attempted to post in Dialogflow forum but there was an error posting. Similar case for raising support withing Dialogflow.
Image of Google simulator agent (works):
Image of public link agent (fails):
Image of Response declared in both webhook js file and within console:
Please find part of my index.js webhook below. I am using Dialogflow's inline editor.
'use strict';
const functions = require('firebase-functions')
const { dialogflow } = require('actions-on-google')
const app = dialogflow()
app.intent('Default Welcome Intent', conv => {
conv.ask('Welcome to Zera! We provide medicine and drug advice. What seems to be bothering you today?')
})
app.intent('QSpecific Problem', (conv, {SpecificProb}) => {
conv.contexts.set('specificprob', 10, {SpecificProb: SpecificProb})
conv.ask(`Do you have these problems before?`)
})
app.intent('QRecurring', (conv, {Recurring}) => {
conv.contexts.set('recurring', 10, {Recurring: Recurring})
if (Recurring === "Recur") {
conv.ask(`Have you taken any medication for this?`);
} else {
const specProb = conv.contexts.get('specificprob')
conv.ask(`How long have you been having this ${specProb.parameters.SpecificProb}?`)
}
})
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app)
I actually wrote in to Dialogflow's support team to seek help. I spoke with Riel, who was very helpful. Please see his reply below:
Your agent works as expected in Actions on Google Simulator because
the library you used is specifically for Actions on Google. The
library you've been using is Actions on Google Node.js client library.
If you want to also use the web demo integration for your responses,
you can use Dialogflow’s fulfillment library that has an integration
with the Google Assistant using AoG client library.
You can refer to this example code for your fulfillment. 'use strict';
const functions = require('firebase-functions');
const { WebhookClient } = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:debug';
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function welcome(agent) {
let conv = agent.conv();
conv.ask('Welcome to my agent!');
agent.add(conv);
}
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
agent.handleRequest(intentMap);
});
Dialogflow's support team is very helpful and their replies are very quick. I recommend you to write in since everyone's issue is different and quite specific! You can reach them at support#dialogflow.com