I can run my solidity smart contract on Node.js but can someone show me how can I connect this contract with a php website to get user id and phone number. I have a form on my php website but not sure how to link these inputs directed to my smart contract? Thanks in advance
import Web3 from "web3";
window.ethereum.request({ method: "eth_requestAccounts" });
const web3 = new Web3(window.ethereum);
export default web3;
Related
i have used ganache cli and connected to metamask. normally everything works fine but after i get an error on metamask internal json rpc error, i am not able to use the account . even if i am not interacting with the smart contract . just normal send in metamask does not work for that account and give internal json rpc error. i had to add another account and it works fine.
is account in ganache gets blocked.
or metamask does some kind of blacklisting.
i tried web3 js to interact with those account using their private key and it works perfectly.
please let me know what is the logic here how my ganache accounts are not working and anything that i am missing.
thank you
i tried to interact with smart contract and it didn’t work for some reason. after that for any transaction on metamask i am getting internal rpc error
I have a Firebase functions project with dev and prod versions. There I'm using auth.generateEmailVerificationLink() to send email verification for a newly created user. Everything works well except in prod environment (testing locally or hosted) the apiKey in the link generated by auth.generateEmailVerificationLink() is not same as Firebase's default apiKey. And clicking that link I get the page with error code:
Try verifying your email again
Your request to verify your email has expired or the link has already been used
Note that when I get the link with the wrong apiKey, if I change it to the right apiKey. the verification works. So it seems the whole problem is related to the wrong apiKey in generated email verification link.
Also to note that the wrong apiKey is not random key but used in project front end for Google Maps apis.
The code itself is simple. (I'm leaving out code which creates user etc as those parts all work perfectly)
-Initializing Admin SDK:
import { initializeApp } from 'firebase-admin/app';
import { getAuth } from 'firebase-admin/auth';
initializeApp();
const auth = getAuth();
export { auth };
-Generating email verification email
const sendEmail = async () => {
const actionCodeSettings = {
// This url is working correctly, it is the same as in Firebase console
// and when changing the wrong apiKey to correct redirecting works correctly
url: process.env.DOMAIN as string,
};
await auth
.generateEmailVerificationLink(email, actionCodeSettings) // email is the email of newly created user
.then((link) => {
// generate email message with link
// generate mailOptions
// use transporter to send email
});
};
Thank you for any help
EDIT
I tested deleting that "wrong" apiKey from GCP credentials page and replaced it with another. Then running the function locally everything worked normally but the "wrong" is still in the verification email link even tho it doesn't exist anymore.
Firebase strongly recommends that if Admin SDK is used in Cloud Functions, among others, initializing the app should be done without parameters.
https://firebase.google.com/docs/admin/setup#initialize-without-parameters
For me it seems something is for some reason pulling that "wrong" and now even deleted apiKey from somewhere to usage.
I solved this by noticing that, unlike in dev project, Web Api Key (Project Settings>General) is different than Web App's firebaseConfig apiKey.
So I added correct permission to this Web Api Key (Identity Toolkit API is required for email verification email) found in GCP credentials and now the cloud function sends email verification emails with correct and working apiKey.
I'm trying swap B-Token for BNB using swapExactTokensForETH on Pancakeswap Router V2
I've also tried swapExactTokensForETHSupportingFeeOnTransferTokens without and success.
It fails with TransferHelper: TRANSFER_FROM_FAILED
When I use pancakeswap.fiance and metamask it works as in this transaction
https://bscscan.com/tx/0x76906d7733566ad9a020994dad44ac7cdddbf5c8d513c769488ae0d9ed96824a
However it fails when I call it from the nodejs script.
I'd really appreciate any help here.
I want to create a passwordless authentication (using Metamask to sign a message; then validate the message on the server and then assign a JWT token). I want the part for signing a message to be written inside a vanilla JavaScript file.
Most of the articles I see online are from 2018 and talk about using web3.eth.personal.sign method from web3 which being injected into the browser by Metamask. However I understand this is no longer the case with Metamask. Now that web3 is not injected anymore, what functions do I call to sign a message with Metamask?
What I've attempted...
I understand there's a window.ethereum object injected into the browser but I can't seem to find an equivalent function in the Metamask documentation for web3.eth.personal.sign
I'm guessing the alternative is to use web3 without window.ethereum but how to I inject this into a vanilla JavaScript file? Also how do I ensure that the message is signed by Metamask if I just use web3 as standalone?
You could use the web3 npm package. Then you can connect it to Metamask with:
import Web3 from "web3";
window.ethereum.request({ method: "eth_requestAccounts" });
const web3 = new Web3(window.ethereum);
This will make metamask popup and ask the user to select an account.
Then to sign a message you can call web3 with:
const dataToSign = "My test message";
const accounts = await web3.eth.getAccounts();
const signature = await web3.eth.sign(dataToSign, accounts[0]);
Documentation: https://web3js.readthedocs.io/en/v1.3.4/web3-eth.html#sign
This will cause Metamask to ask the user to sign the data with their currently active account. I'm not sure how to validate if the signature is correct.
I have a client that wants to be able to create xero invoices from a custom backend plugin that I have created in WordPress. I understand the xero api docs and what data to pass to the api to create a new invoice but I have to somehow authenticate the user so that they can send data to the api. So far I have created my xero app with a client id and client secret which I believe is required to help authenticate the api request.
But how can I authenticate the api request?
If I do simple request like this it fails:
jQuery(document).ready(function ($) {
$.ajax({
url: 'https://api.xero.com/connections',
error = (res) => {
console.log(res);
},
success = (res) => {
console.log(res);
}
});
});
I'd first recommend using the official xero PHP sdk, however I'm not sure if you are able to import packages to Wordpress like this. I've done some wordpress but I know there are some limitations with importing certain external libraries.
https://github.com/XeroAPI/xero-php-oauth2
However as an alternate solution, theres a recent blogpost on using a raw OAuth2.0 library to connect to XeroAPI manually though. This might set you on the right direction!
https://medium.com/#sid.maestre/use-php-to-connect-with-xero-31945bccd037