Getting No RPC Url available for chainId: 137 error when trying to use Custom RPC with WalletConnect - rpc

My code:
import { providers } from 'ethers';
import WalletConnectProvider from '#walletconnect/web3-provider';
const walletConnectProvider = new WalletConnectProvider({
rpc: {
// I got this from https://github.com/DefiLlama/chainlist/blob/main/constants/extraRpcs.json
80001: 'https://rpc.ankr.com/polygon_mumbai',
},
chainId: 80001,
});
// Enable session (triggers QR Code modal)
await walletConnectProvider.enable();
// this is the line I'm getting error
const web3Provider = new providers.Web3Provider(walletConnectProvider);
It does create web3Provider but it shows this error in the console No RPC Url available for chainId: 137 even though I'm using 80001 as chainId.
After this, when I do
console.log(await web3Provider.getNetwork())
it logs
{name: 'matic', chainId: 137, ensAddress: null, ...}
But I never used 137. Does anyone know why it does that?

Related

Gram-js. Problem with message.sendMedia, channels.editPhoto

I am creating a telegram client to create templates channels. I got mainly all the functionality I wanted but I got stuck with all the functionality that implies upload media:
message.sendMedia (https://gram.js.org/tl/messages/SendMedia)
channel.editPhoto (https://gram.js.org/tl/channels/EditPhoto)
When I use the message.sendMedia method I always get this error:
Error: Disconnect (caused from messages.SendMedia)
at /Users/apple/Desktop/Projects/Telegram-Bots/gram-js/node_modules/telegram/extensions/MessagePacker.js:107:33
at Array.forEach (<anonymous>)
at MessagePacker.rejectAll (/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/node_modules/telegram/extensions/MessagePacker.js:105:29)
at MTProtoSender._disconnect (/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/node_modules/telegram/network/MTProtoSender.js:249:25)
at MTProtoSender.disconnect (/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/node_modules/telegram/network/MTProtoSender.js:168:20)
at TelegramClient.disconnect (/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/node_modules/telegram/client/telegramBaseClient.js:163:32)
at _updateLoop (/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/node_modules/telegram/client/updates.js:177:26)
And this one is the code I am executing:
const sendMedia = async (channelId) => {
const file = await client.uploadFile({
file: new CustomFile(
'stakazo.jpeg',
fs.statSync(
'/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/images/xxxxx.jpeg'
).size,
'/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/images/xxxxxx.jpeg'
),
workers: 1,
});
const result = await client.invoke(
new Api.messages.SendMedia({
peer: channelId,
media: new Api.InputMediaUploadedPhoto({
file: file,
ttlSeconds: 43,
}),
message: 'Hello there!',
randomId: BigInt('-4156887774564'),
scheduleDate: 43,
})
);
};
I am really stuck here. I thought I might be a problem with the image but did not get to find out anything.
We can use this code to send the file(image, doc etc.).
await client.sendMessage("me", {
message: "test send file", //leave it empty if don't want to send the message with the image
file: fileName,
});
For more information refer to this article -> https://gram.js.org/beta/classes/TelegramClient.html#sendFile

How can I fix IPC error "Error invoking remote method, an object could not be cloned" in Electron?

The whole error message is the following:
Error: Error invoking remote method 'MY-IPC-CHANNEL': Error: An object
could not be cloned. at EventEmitter.o.invoke
(electron/js2c/renderer_init.js:71)
The electron/js2c/renderer_init.js:71 line is not my original line of code, but a compiled one.
I'm trying to send a POST request in order to get my Google access token, so that I can work with Google Drive's API. Currently I'm stuck trying to communicate between the renderer process and the main process by giving the main process the code I got from Google and making it send a POST request to the auth server. I have no problem establishing the connection but when I try to do it while sending an HTTP request I get the error above.
// ******* MAIN *******
function exchangeCodeForAccessToken(code: string) {
const clientID = "My Google client ID";
const clientSecret = "My Google client secret";
const body = {
code: code,
client_id: clientID,
client_secret: clientSecret,
redirect_uri: "http://localhost:4000",
grant_type: "authorization_code",
};
const body2 = `code=${code}&
client_id=${clientID}&
client_secret=${clientSecret}&
grant_type=authorization_code`;
// return fetch("https://oauth2.googleapis.com/token", {
// method: "POST",
// body: body
// });
return axios.post("https://oauth2.googleapis.com/token", body);
}
Here's the main handle:
// ******* MAIN *******
ipcMain.handle(
OAUTH2_ACCESS_TOKEN_REQUEST_CHANNEL,
async (event, code: string) => await exchangeCodeForAccessToken(code)
);
And the renderer invoke function:
// ******* RENDERER *******
function exchangeCodeForAccessToken(code: string) {
ipcRenderer.invoke(OAUTH2_ACCESS_TOKEN_REQUEST_CHANNEL, code).then((response) => {
console.log(response);
}).catch((error) => {
//TODO Improve error handling
console.log(error);
});
}
I tried sending the request through the net module from Electron. I also tried with the electron-fetch module, which is supposed to be an Electron integrated version of Node's fetch module. And finally I tried with the axios module, but it kept throwing the same error. I thought it had something to do with object serialization through IPC but then I tried just using the function without returning its promise and the same error kept popping up. Which means that the error is not only appearing when the promise is being returned but whenever the HTTP request function is being called. I also tried sending the request with both the object version of the request and its string version, hence the body and body2.
I don't know what I'm missing, and I'm so close to integrating Google login into my desktop app.
I thought it had something to do with object serialization through IPC but then I tried just using the function without returning its promise and the same error kept popping up.
It is an IPC error. You're returning the full response object, which presumably contains some properties with methods and/or other non-cloneable values. You need to make sure that the returned value can be cloned and sent to the renderer, for example:
ipcMain.handle(
OAUTH2_ACCESS_TOKEN_REQUEST_CHANNEL,
async (event, code) => {
const response = await exchangeCodeForAccessToken(code);
const {status, data} = response;
return {status, data};
}
);
I'm not sure how you called the function in your attempt to fix this, but I just ran this in Electron and it works without issues.
EDIT: Assuming response is coming from a fetch call (use response.json() if the data is JSON):
ipcMain.handle(
OAUTH2_ACCESS_TOKEN_REQUEST_CHANNEL,
async (event, code) => {
const response = await exchangeCodeForAccessToken(code);
const data = await response.text();
return data;
}
);

Test suite for smart home doesn't pass with one action, but it does with another one with the exact same code

we've developed a smart home action for Google Assistant and our "staging action" passed the test suite for smart home. Now that we wanted to get the "production action" certified, the test suite didn't pass, not a single command worked. The devices' states changed correctly, but the test suite returned the following error: AssertionError: Expected state to include: {"on":true}, actual state: {}: expected false to be true
We've had the problem before with the "staging action" and identified it to be a HomeGraph Sync problem. We fixed it and afterwards it worked. The "production action's" code is the exact same as the "staging action's" and the settings are also the same. So we have no idea what we could do to make the test suite pass. Does anyone have an idea of what the problem might be?
Here is an excerpt of our code:
const { smarthome } = require('actions-on-google');
// creating app in constructor
this._app = smarthome({ jwt, debug: this._options.debug || false });
// code-snipped sending state to HomeGraph after creating the state object from our device states
console.info('Report state:');
console.info(inspect(state, {depth: null, showHidden: false}));
this._app.reportState(state)
.then(res => console.info('report state succeeded', res))
.catch(err => console.error('report state failed', err));
And here is the corresponding log:
Report state:
{
requestId: 'c82c0c20-a10d-4ded-a456-319109188501',
agentUserId: '730f1842168ade4dcf9be3e40ea279e7ac4e6f21c002c09909f9d9a0341d2214',
payload: {
devices: {
states: {
'500dc011398fd3c191efdfa8e13a1062f7ef4d1c': { on: true, online: true }
}
}
}
}
report state succeeded {
"requestId": "c82c0c20-a10d-4ded-a456-319109188501"
}
In case of an error we expect something like:
404: agentUserId unknown or HomeGraph not enabled
401: access rights misconfigured
or any other error
but it succeeds.
EDITED:
We adjusted our code by reading the state from HomeGraph directly after sending it to HomeGraph in order to see whether HomeGraph gets anything from us at all:
const auth = new google.auth.GoogleAuth({
credentials: jwt,
scopes: ['https://www.googleapis.com/auth/homegraph']
});
this._hg = google.homegraph({
version: 'v1',
auth: auth,
});
this._app = smarthome({ jwt, debug: this._options.debug || false });
this._app.reportState(state).then(async res => {
const request = {
requestBody: {
agentUserId: state.agentUserId,
inputs: [{
payload: {
devices: Object.keys(state.payload.devices.states).map(id => ({id}))
}
}]
}
};
console.info(require('util').inspect(request, {depth: null}));
const readStates = await this._hg.devices.query(request);
console.info('########## STATES in HOMEGRAPH #######################');
console.info(readStates.data);
return res;
})
.catch(err => console.error('report state failed', err));
The state is empty.
We also implemented a simple node.js app to read all device states via HomeGraph API. All device states are empty at any time.
The main question is: Why does calling this._app.reportState(state) never run into catch handler? There must be something wrong with our sending the state to HomeGraph, but we do not get any error back...?
Thanks! The problem has sorted itself out somehow. Maybe Google had a bug, but without doing anything on our part the tests pass now.
If you're getting {} as the actual state value, then it seems like the Test Suite is unable to read data from the Home Graph. There are two likely reasons for this.
In your production project, your test account has a different agentUserId
Your production project will have a different service account key than your staging project. You may be uploading the wrong key, which causes the Home Graph API calls in the test suite to be unsuccessful.

First step on Google API + GMAIL = bad request

I'm very new on Google API, Eventually I want to send emails using it. But for now I'm trying something a little bit simpler (and then build it up).
List all emails in the inbox.
From Gmail > API > Reference, I followed these steps:
On Google API Console:
Created my application.
Under API & Services > Credentials I created a user with Project/Owner role (just to make sure there is no permission problems in this step).
Then I created a key and download the json file.
At API & Services > Library I enabled Gmail.
And using the Reference I put together this snippet:
app.ts
import { google } from 'googleapis';
import credentials from './credentials';
async function main() {
const auth = new google.auth.GoogleAuth({
credentials,
scopes: [
'https://mail.google.com/',
'https://www.googleapis.com/auth/gmail.compose',
'https://www.googleapis.com/auth/gmail.modify',
'https://www.googleapis.com/auth/gmail.readonly',
'https://www.googleapis.com/auth/gmail.metadata'
]
});
const authClient = await auth.getClient();
const gmail = google.gmail({ version: 'v1', auth: authClient });
const data = await gmail.users.messages.list({ userId: 'me' });
console.log(data);
}
main().catch(console.log);
package.json
...
"dependencies": {
googleapis": "^48.0.0"
}
...
Every time I ran this snippet I got:
[01] GaxiosError: Bad Request
[02] at Gaxios._request (~\node_modules\gaxios\build\src\gaxios.js:85:23)
...
[06] response: {
...
[35] status: 400,
[36] statusText: 'Bad Request',
[37] request: {
[38] responseURL: 'https://www.googleapis.com/gmail/v1/users/me/messages'
...
I tried many diferent configurations on Google API Console. Tried to change the scope (list of urls from line 8 to 12) for many others, change the credentials.json to a .js and .ts format, put in a global variable (GOOGLE_APPLICATION_CREDENTIALS) instead of a direct import. But despite of all my attempts, I got aways the same error.
How can I fix that?
Check out example from here which does exactly what you want. They seem use a sampleclient instead of a credentials library.

rally node sdk giving back Error: getaddrinfo ENOTFOUND

I keep getting the following error response from node when trying to run a read call to rally:
Error: getaddrinfo ENOTFOUND rally1.rallydev.com rally1.rallydev.com:443
I am using the Rally Node SDK, and node v7. I am on a local machine. It is successfully reaching and logging the 'releaseoid' before the 'try'.
I feel like I am not specifying http (which I was before and now completely commented out the server, letting the SDK default it). But it is continuing to give back that error. I could not find (or possibly understand) other general Node guidance that may address this situation. I am not clear where port 443 is coming from as I am not specifying it. Is the SDK adding it?
If I specify the server address without http:
server: 'rally1.rallydev.com',
I still get an error, but this time:
Error: Invalid URI "rally1.rallydev.com/slm/webservice/v2.0null
I am new to Node and not sure if I am having a problem with Node or the Rally Node SDK.
Code below.
var rally = require('rally');
var rallyApi = rally({
apiKey: 'xx',
apiVersion: 'v2.0',
//server: 'rally1.rallydev.com',
requestOptions: {
headers: {
'X-RallyIntegrationName' : 'Gather release information after webhook',
'X-RallyIntegrationVendor' : 'XX',
'X-RallyIntegrationVersion' : '0.9'
}
}
});
// exports.getReleaseDetails = function(releaseoid, result) {
// console.log('get release details being successfully called');
//
//
//
// }
module.exports = {
getReleaseDetails: async(releaseoid) => {
console.log(releaseoid);
try {
let res = await
rallyApi.get({
ref: 'release/' + releaseoid,
fetch: [
'Name',
'Notes',
'Release Date'
]
//requestOptions: {}
});
res = await res;
console.log(res);
} catch(e) {
console.error('something went wrong');
console.log(e);
}
}
}
That mostly looks right. I haven't tried to use async/await with the node toolkit yet- it would be interesting to see if that works. It should, since get and all the other methods return promises in addition to handling standard node callback syntax.
But anyway, I think the issue you're having is a missing leading / on your ref.
rallyApi.get({
ref: '/release/' + releaseOid
});
Give that a shot?
As for the network errors, is it possible that you're behind a proxy on your network? You're right though, https://rally1.rallydev.com is the default server so you shouldn't have to specify it. FYI, 443 is just the default port for https traffic.

Resources