Mint a NFT with React, Error: cannot estimate gas; transaction may fail or may require manual gas limit - reactjs

I created a smart contract based on “Build your own Ethereum NFT Collection” tutorial, in buildspace, using the Goerli Testnet.
That contract successfully worked and I confirmed that it was minted on Goerli Etherscan and the Opensea Testnet.
However, when I used the same code to deploy the smart contract to the Ethereum Mainnet, the smart contract did not go through.The console of Chrome DevTools printed the following error:
Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See:
https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT
] (reason=“execution reverted”, method=“estimateGas”, transaction= … (…)
The code I wrote following the tutorial is at this Github repository:
https://github.com/miu-null/smartcontract/
and my mint page is here:
https://miu-null.github.io/mint/
Could it be that there is an issue with my contract code? or just something wrong in my React code? I would be grateful if I could get any help. As you may know, I just completed the tutorial and I’m having trouble understanding this error. Thank you in advance for your response.
I tried to edit to add estimate gasPrice in my React code,
`for example :
const gasPrice = await provider.getGasPrice();
const gasPriceInGwei = ethers.utils.formatUnits(gasPrice, "gwei");
const currGas = setGasPrice(gasPriceInGwei);
`
and then..
honestly I'm not sure that currGas(it means gasPrice) is connected to my contract.

Related

Difference between JSON-RPC Endpoints of BSC, https://bsc-dataseed1.binance.org:443 vs https://data-seed-prebsc-1-s1.binance.org:8545/?

I was still doing well with JSON-RPC Endpoint (https://bsc-dataseed1.binance.org:443) from https://docs.binance.org/smart-chain/developer/rpc.html; normally it's only about 5X,XXX
var web3 = new Web3('https://bsc-dataseed1.binance.org:443');
var web3 = new Web3('https://data-seed-prebsc-1-s1.binance.org:8545/');
But today Gas Limit is too high (81,344), so I tried to lookup many and found some endpoints, one of them: https://data-seed-prebsc-1-s1.binance.org:8545/
With same contract, same data & nonce, I used web3.eth.estimateGas then Gas Limit of the new one is 22,848; it's just same to fee for BNB transfer.
Why they have too different fees like that, someone may help me understand?
It's safe to use with the new one?
Actually, data-seed-prebsc-1-s1.binance.org:8545 is testnet rpc !
Use it if you wanna test stuff without burning "real" BNB for gas (testnet bnb has no value lol).
Have a nice day :D

Why Coinbase API doesn't return the sell price for XRP?

For various cryptocurrencies, the API returns a valid response with a sell price or spot price. Just like in this example:
❯ curl 'https://api.coinbase.com/v2/prices/XLM-EUR/sell'
{"data":{"base":"XLM","currency":"EUR","amount":"0.32"}}
But for XRP, it returns an error. Why? 'm guessing that it may be related to the fact that Coinbase has suspended buying XRP, but selling it is still possible so getting the rate may be required.
❯ curl 'https://api.coinbase.com/v2/prices/XRP-EUR/sell'
{"errors":[{"id":"not_found","message":"Invalid base currency"}]}
I'm having the same problem using the wallet client with the code below.
coinbase.wallet.client.Client(
my_key, my_secret, api_version=my_version,
).get_spot_price(currency_pair='XRP-USD')
It would be great to see this resolved.

Use token obtained using R package AzureAuth to Query data

I am using the following code to get an access token using AzureAuth package in R
library (AzureAuth)
AuthToken <- get_azure_token("120d688d-1518-4cf7-bd38-182f158850b6",tenant="72f988bf-86f1-41af-91ab-2d7cd011db47", app="1950a258-227b-4e31-a9cf-717495945fc2");
However, I don't see any examples on how to use the obtained AuthToken in query data from an API?
Appreciate any help!
Pls point out my mistake if I misunderstand your question.
=======================Update=======================
Yes, I found some documents and I followed the sample. And I found that, if I wanna to call graph api, I just need to 'install.packages("AzureGraph")', and with this package I can reach my goal. And if I need to use AzureR to do some other operations on azure, the ducoment above has offered an example to illustrate how to create a resource group and storage account in AzureRMR, and a registered app in AzureGraph.
===================================================
Getting started with httr
I use this code to get httr get request, and http post request is similar, look up the document above for more details:
a <- GET("https://graph.microsoft.com/v1.0/me", add_headers(Authorization = "Bearer <accesstoken>"))
I just figured out the syntax. I found it difficult on two counts
Syntax for POST command. There are lot of examples for GET command but not many on POST
Getting to access_token. However once I started using R Studio, I was able to inspect the object and find the right field. Here is the syntax that worked for me
res <- POST(EnvironmentFqdnUrl,add_headers(Authorization = paste("Bearer", AuthToken$credentials$access_token)), body = upload_file("body.json"), verbose())
print(res)

IBMQProvider issue

I successfully installed and ran a couple of circuits on a backend the other day (essex).
Everything was ok, results came up, but the next day, once I wanted more QC, I could not manage to get a provider.
I have looked into my account (active), looked into the package (up-to-date), and a new file in the project. I also already disabled and enabled the account without problems, but I keep having this error.
Code
from qiskit import IBMQ
IBMQ.active_account()
IBMQ.providers()
provider = IBMQ.get_provider(hub='ibm-q', group='open', project='main')
and I get:
>~/my_environment_name/lib/python3.7/site-packages/qiskit/providers/ibmq/ibmqfactory.py in get_provider(self, hub, group, project)
425 raise IBMQProviderError('No provider matches the specified criteria: '
426 'hub = {}, group = {}, project = {}'
--> 427 .format(hub, group, project))
428 if len(providers) > 1:
429 raise IBMQProviderError('More than one provider matches the specified criteria.'
IBMQProviderError: 'No provider matches the specified criteria: hub = ibm-q, group = open, project = main'
I would like to know where I am wrong, I look forward to keep learning thru the backends efficiently.
Thank you in advance
This means that there is no provider that matches all the criteria you specified, so in that hub, group and project. This could be because your account hasn't loaded correctly, so check to see if anything is returned from IBMQ.providers(). If there isn't anything load your account using IBMQ.load_account(). The other issue could be that there are genuinely no backends that meet those criteria, so try running IBMQ.get_provider() instead.
Try to use API token to enable your IBMQ account.
from qiskit import IBMQ
provider = IBMQ.enable_account("your-api-key") # We load our account
provider.backends() # We retrieve the backends to check their status
for b in provider.backends():
print(b.status().to_dict())
Create IBM Quantum account if you don't have one, then use the API token that available in the dashboard as enable_account() method argument to resolve this issue.
For More: https://quantum-computing.ibm.com/lab/docs/iql/manage/account/ibmq
https://quantum-computing.ibm.com/
https://www.ibm.com/account/reg/us-en/signup?formid=urx-19776&target=https%3A%2F%2Flogin.ibm.com%2Foidc%2Fendpoint%2Fdefault%2Fauthorize%3FqsId%3D70b061b4-7c64-4545-a504-a8871f2d414f%26client_id%3DN2UwMWNkYmMtZjc3YS00

How to fix memory leak in my application?

In my GAE app I add rows to Google Spreadsheet.
taskqueue.add(url='/tabletask?u=%s' % (user_id),
retry_options=taskqueue.TaskRetryOptions(task_retry_limit=0),
method='GET')
class TableTaskHandler(webapp2.RequestHandler):
def get(self):
user_id = self.request.get('u')
if user_id:
try:
tables.add_row(
user_id
)
except Exception, error_message:
pass
def get_google_api_service(scope='https://www.googleapis.com/auth/spreadsheets', api='sheets', version='v4'):
''' Login to Google API with service account and get the service
'''
service = None
try:
credentials = AppAssertionCredentials(scope=scope)
http = credentials.authorize(httplib2.Http(memcache))
service = build(api, version, http=http)
except Exception, error_message:
logging.exception('Failed to get Google API service, exception happened - %s' % error_message)
return service
def add_row(user_id, user_name, project_id, question, answer, ss_id=SPREADSHEET_ID):
service = get_google_api_service()
if service:
values = [
[
user_id, user_name, project_id, question, answer # 'test1', 'test2'
],
# Additional rows ...
]
body = {
'values': values
}
# https://developers.google.com/sheets/api/guides/values#appending_values
response = service.spreadsheets().values().append(
spreadsheetId=ss_id,
range='A1:E1000',
valueInputOption='RAW',
body=body).execute()
I add many tasks with different row values.
In result I get critical errors 'Exceeded soft private limit of 128 Mb with 158 Mb' after servicing 5 requests in total.
What could be wrong here?
At first glance there’s nothing special in your code that might lead to a memory leak.
I don’t think anybody can locate it unless he’s very deeply familiar with the 3rd party libraries used and their existing bugs. So I’d approach the problem as follows:
First lets find out where exactly memory is leaking and whether it’s leaking at all.
Refer to tracemalloc, memory_profiler, heapy or whatever else you’re familiar with. Most profilers available are listed here Which Python memory profiler is recommended?
Expected outcome: you clearly know where exactly the memory is leaking, up to a code line / python expression
If the problem is in a 3rd party code, try to dig deeper into its code and figure out what’s up there
Depending on p.2 outcome
a. Post another SO question like ‘why this python code excerpt leads to a memory leak’ - ideally it should be a standalone code snippet that leads to a weird behavior free of any third party libraries and reproducible locally. Environment specification - at least python version, is appreciated
b. If the problem is in a 3rd party library and you’ve located the problem, open a bug report on github/anywhere the target project is hosted
c. If the problem is clearly in a 3rd party library and you’re unable to find the cause, open a ticket describing the case with the profiler's report attached
It seems to be that you are running instance class B1 or F1, which has a memory limit of 128 MB.
A possible solution would be to use a higher instance class. But please keep in mind that choosing a different instance class will have impact on your pricing and quotas.

Resources