Create silently fails with invalid connection url
This all works with genache, but fails silently with ropsten and infura:
Edit: The code below produces an invalid url for infura, but I would hope to see an error when this is the case.
networks.js:
const fs = require("fs");
const HDWalletProvider = require("@truffle/hdwallet-provider");
const MNEMONIC = fs.readFileSync("./mnemonic", "utf8").trim();
const USE_DEFAULT = void 0;
const PATH = "m/44'/60'/0'/0/";
const getUrlFromNetwork = ({ protocol, host, port = 80 }) =>
`${protocol}://${host}:${port}`;
const development = {
protocol: "http",
host: "localhost",
port: 7545,
gas: 5000000,
gasPrice: 5e9,
networkId: "*",
provider: () =>
new HDWalletProvider(
MNEMONIC,
getUrlFromNetwork(development),
USE_DEFAULT,
USE_DEFAULT,
USE_DEFAULT,
PATH
)
};
const ropsten = {
protocol: "https",
host: "ropsten.infura.io/v3/my_project_id",
port: 80,
gas: 5000000,
gasPrice: 5e9,
networkId: "*",
provider: () =>
new HDWalletProvider(
MNEMONIC,
getUrlFromNetwork(ropsten),
USE_DEFAULT,
USE_DEFAULT,
USE_DEFAULT,
PATH
)
};
const networks = { development, ropsten };
module.exports = { networks };
The npx oz create is failing silently. I made sure that it isn't in fact using the default addresses provided with genache.
Let me know if there's any more info you need from me. If you can see what's wrong with my code, I would be happy to PR proper error handling here.
npx oz accounts also fails silently, so I'm guessing that it's anything that makes a network request.
Interestingly enough, I wanted to see what network calls were being made so I set up a proxy to log out all the requests/responses and magically everything worked. Here's my code:
const http = require("http");
const https = require("https");
const PROXY_URL = "https://ropsten.infura.io/v3/my_project_id";
const getDataLoggerWithLabel = label => data => {
console.log(`${label} data:`);
console.log(data);
console.log();
};
http
.createServer((req, res) => {
const proxy = https.request(PROXY_URL, { method: "POST" });
req.setEncoding("utf8");
req.on("data", getDataLoggerWithLabel("request"));
proxy.on("response", proxy => {
proxy.setEncoding("utf8");
proxy.on("data", getDataLoggerWithLabel("response"));
proxy.pipe(res);
});
req.pipe(proxy);
})
.listen(8000);
and adjustments to networks.js:
const ropsten = {
// protocol: "https",
// host: "ropsten.infura.io/v3/my_project_id",
// port: 80,
protocol: "http",
host: "localhost",
port: 8000,
gas: 5000000,
gasPrice: 5e9,
networkId: "*",
provider: () =>
new HDWalletProvider(
MNEMONIC,
getUrlFromNetwork(ropsten),
USE_DEFAULT,
USE_DEFAULT,
USE_DEFAULT,
PATH
)
};
I so my problem is definitely with the provider connection, but this github issue is still valid as the cli should not just fail silently.
Side note:
The { "params":["latest",true], "method":"eth_getBlockByNumber" } isn't the most efficient method to use, something like { "params":["latest",true], "method":"eth_blockNumber" } is much cheaper. I guess I should bring that up with web3?
Hi @richardpringle,
I’m sorry you are having this issue. We want to get you connected and then we can look at what can be done about the CLI failing silently.
I assume that you are replacing my_project_id with a valid Infura project ID.
I have posted in the Community Forum a network.js for Rinkeby along with a link to the Learn guide documentation on connecting to a public test network. I suggest looking at the sample network.js
https://forum.openzeppelin.com/t/what-is-the-network-js-to-connect-to-rinkeby/2450/2?u=abcoathup
Hey @abcoathupm thanks for the quick response! I figured out that I was naively appending the port to the host when the host actually contains a path for infura. I fixed this by using Node's url module instead of building the url myself.
However, that does not change the fact that the cli was failing silently when it wasn't connecting. I would love to PR the fix if someone can point me to the proper location to do so.
Hi @richardpringle! I’m sorry that you had this issue.
We have been able to reproduce this issue by following these steps:
Using an invalid Infura project ID in network.js to connect to a public test network (as setup per: https://docs.openzeppelin.com/learn/connecting-to-public-test-networks) using a command that attempts to connect to the network, such as oz accounts fails silently.
$ npx oz accounts
? Pick a network rinkeby
network.js
const { mnemonic } = require('./secrets.json');
const HDWalletProvider = require('@truffle/hdwallet-provider');
const projectId = 'invalid_Infura_projectId'
module.exports = {
networks: {
rinkeby: {
provider: () => new HDWalletProvider(
mnemonic, `https://rinkeby.infura.io/v3/${projectId}`
),
networkId: 4,
gasPrice: 10e9
}
},
};
Thanks so much for reporting it! The project owner will review and triage this issue during the next week.
Please wait until we have discussed this idea before writing any code or submitting a Pull Request, so we can go through the design beforehand. We don’t want you to waste your time!