ethers: processing response error code -32000, SERVER_ERROR on BSC testnet while trying to approve on MetaMask - metamask

I am trying to get MetaMask to popup to approve a dapp to use my erc20 tokens like:
const provider = new ethers.providers.JsonRpcProvider(url); // url === bsc testnet rpc
const erco20Contract = new ethers.Contract(
erco20ContractAddress,
erc20Abi,
provider.getSigner(metamaskAddress)
);
await erco20Contract.approve(dappContractAddress, amount);
This code used to work in the past (2 or 3 months ago). Now when I call this same code I get
processing response error (body="{"jsonrpc":"2.0","id":51,"error":{"code":-32000,"message":"unknown account"}}\n", error={"code":-32000}, requestBody="{"method":"eth_sendTransaction","params":[{"gas":"0xac9f","from":"<my_metamask_address>","to":"<dapp_address>","data":"0x095ea7b300000000000000000000000078c18d3d5f86c9e3e14c13b8065018acd0d76c11000000000000000000000000000000000000000000000000016345785d8a0000"}],"id":51,"jsonrpc":"2.0"}", requestMethod="POST", url="https://data-seed-prebsc-1-s1.binance.org:8545/", code=SERVER_ERROR, version=web/5.7.0)
I'm now noticing part of the error message says code=SERVER_ERROR, so did Binance change something on their end?
Could it be that MetaMask or ethers updated with breaking changes? I literally have no idea what to do. Please help!

Related

connect ETIMEDOUT 137.116.128.188:443 for bot FRAMEWORK, can be extended

So I have a request that is expected to run for at least 1 min. before it will give a response
To help aid user on not doing anything while my request is still running, I set some sendTyping activities:
For censoring production codes work sensitive information
, this is generally how my code looks like:
var queryDone = "No";
var xmlData = '';
let soappy = soapQuery("123", "456", "789","getInfo");
soappy.then(function (res) {
queryDone = 'Yes';
xmlData = res;
console.log(xmlData);
}, function (err) {
queryDone = 'Timeout';
})
while (queryDone == 'No') {
await step.context.sendActivity({ type: 'typing' });
}
where soapQuery() is a function that sends and returns the POST request which looks like this:
return new Promise(function (resolve, reject) {
request.post(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
resolve(body);
}
else {
reject(error);
}
})
})
Problem comes because of this 1 minute response, (it's not really negotiable as the server requires at least 1 min to process it, due to large number of data and validation of my request).
Though after 1 minute, the console does print the response, sadly even before this, the bot already time out.
Any suggestion how to fix this, or extend time out of the bot?
I need the sendtyping activity so that user understands that the request is not yet done. And again, it really takes 1 minute before my request responds.
Thank you!
So, the reason that this happens is that HTTP requests work a little bit differently in the Bot Framework than you might expect. Here's how it works:
So basically, what's happening in your scenario is:
User sends HTTP POST
Bot calls your soapQuery
Bot starts sending Typing Indicators
soapQuery completes
Bot finally sends an HTTP Response to the HTTP POST from step #1, after the request has already timed out, which happens after 15 seconds
To fix this, I would:
Use showTypingMiddleware to send the typing indicator continuously and automatically until the bot sends another message (this gets rid of your blocking while loop)
Once soapQuery finishes, the bot will have lost context for the conversation, so your soappy.then() function will need to send a proactive message. To do so, you'll need to save a reference to the conversation prior to calling soappy(), and then within the then() function, you'll need to use that conversationReference to send the proactive message to the user.
Note, however, that the bot in the sample I linked above calls the proactive message after receiving a request on the api/notify endpoint. Yours doesn't need to do that. It just needs to send the proactive message using similar code. Here's some more documentation on Proactive Messages

Authenticating a Xamarin Android app using Azure Active Directory fails with 401 Unauthorzed

I am trying to Authenticate a Xamarin Android app using Azure Active Directory by following article here:
https://blog.xamarin.com/authenticate-xamarin-mobile-apps-using-azure-active-directory/
I have registered a native application with AAD; note that i havent given it any additional permissions beyond creating it.
Then i use the below code to authenticate the APP with AAD
button.Click += async (sender, args) =>
{
var authContext = new AuthenticationContext(commonAuthority);
if (authContext.TokenCache.Count > 0)
authContext = new AuthenticationContext(authContext.TokenCache.ReadItems().GetEnumerator().Current.Authority);
authResult = await authContext.AcquireTokenAsync(graphResourceUri, clientId, returnUri, new PlatformParameters(this));
SetContentView(Resource.Layout.Main);
doGET("https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/OPSLABRG/providers/Microsoft.Compute/virtualMachines/LABVM?api-version=2015-08-01", authResult.AccessToken);
};
private string doGET(string URI, String token)
{
Uri uri = new Uri(String.Format(URI));
// Create the request
var httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
httpWebRequest.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + token);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "GET";
// Get the response
HttpWebResponse httpResponse = null;
try
{
httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
}
catch (Exception ex)
{
Toast.MakeText(this, "Error from : " + uri + ": " + ex.Message, ToastLength.Long).Show();
return null;
}
}
This seems to be getting a token when using a Work account.
Using a valid hotmail account throws error A Bad Request was received.
However the main problem is when i try to retrieve VM details using REST.
the REST GET method fails with 401 Unauthorized error even when using the Work account.
I am not sure if the code is lacking something or if i need to give some additional permissions for the App. This needs to be able to support authenticating users from other tenants to get VM details.
Any guidance is appreciated.
note that i havent given it any additional permissions beyond creating
it.
This is the problem here.
In order for you to call the Azure Management API https://management.azure.com/, you must first register your application to have permissions to call this API.
You can do that as a part of your app registration like so:
Only at that point, will your app be authorized to call ARM, and your calls should start to work.
According to your description, I checked this issue on my side. As Shawn Tabrizi mentioned that you need to assign the delegated permission for accessing ARM Rest API. Here is my code snippet, you could refer to it:
var context = new AuthenticationContext($"https://login.windows.net/{tenantId}");
result = await context.AcquireTokenAsync(
"https://management.azure.com/"
, clientId, new Uri("{redirectUrl}"), platformParameter);
I would recommend you using Fiddler or Postman to simulate the request against ARM with the access_token to narrow this issue. If any errors, you could check the detailed response for troubleshooting the cause.
Here is my test for retrieving the basic information of my Azure VM:
Additionally, you could leverage jwt.io for decoding your access_token and check the related properties (e.g. aud, iss, etc.) as follows to narrow this issue.

open https connection (distance matrix api)

I am trying to use google distance matrix api
I'm using this url through volley request, and i get a VolleyError (onErrorResponse):
https://maps.googleapis.com/maps/api/distancematrix/json?origins="+pickup+"&destinations="+destination+"&key=API-KEY
I have tried to open the url using an intent like this :
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
but I get this error:
android.content.ActivityNotFoundException: No Activity found to handle
Intent {
act=android.intent.action.VIEW
dat=https://maps.googleapis.com/maps/api/distancematrix/json?
origins=Hai Si Redouane, Oran
&destinations=Place Premier November 1954, Oran, Algeria
&key=API-KEY
}
Notice: I am using a real device and url is working fine when I open it from browser

Get "API key is missing" error when querying account details to Mailchimp API 3.0 using RestSharp

When using RestSharp to query account details in your MailChimp account I get a "401: unauthorized" with "API key is missing", even though it clearly isn't!
We're using the same method to create our RestClient with several different methods, and in all requests it is working flawlessly. However, when we're trying to request the account details, meaning the RestRequest URI is empty, we get this weird error and message.
Examples:
private static RestClient CreateApi3Client(string apikey)
{
var client = new RestClient("https://us2.api.mailchimp.com/3.0");
client.Authenticator = new HttpBasicAuthenticator(null, apiKey);
return client;
}
public void TestCases() {
var client = CreateApi3Client(_account.MailChimpApiKey);
var req1 = new RestRequest($"lists/{_account.MailChimpList}/webhooks", Method.GET);
var res1 = client.Execute(req1); // works perfectly
var req2 = new RestRequest($"automations/{account.MailChimpTriggerEmail}/emails", Method.GET);
var res2 = client.Execute(req2); // no problem
var req3 = new RestRequest(Method.GET);
var res3 = client.Execute(req3); // will give 401, api key missing
var req4 = new RestRequest(string.Empty, Method.GET);
var res4 = client.Execute(req4); // same here, 401
}
When trying the api call in Postman all is well. https://us2.api.mailchimp.com/3.0, GET with basic auth gives me all the account information and when debugging in c# all looks identical.
I'm trying to decide whether to point blame to a bug in either RestSharp or MailChimp API. Has anyone had a similar problem?
After several hours we finally found what was causing this..
When RestSharp is making the request to https://us2.api.mailchimp.com/3.0/ it's opting to omit the trailing '/'
(even if you specifically add this in the RestRequest, like: new RestRequest("/", Method.GET))
so the request was made to https://us2.api.mailchimp.com/3.0
This caused a serverside redirect to 'https://us2.api.mailchimp.com/3.0/' (with the trailing '/') and for some reason this redirect scrubbed away the authentication header.
So we tried making a
new RestRequest("/", Method.GET)
with some parameters (req.AddParameter("fields", "email")) to make it not scrub the trailing '/', but this to was failing.
The only way we were able to "fool" RestSharp was to write it a bit less sexy like:
new RestRequest("/?fields=email", Method.GET)

Paypal Invoice SDK Service Call + Express Checkout + Recurrying Payment issue

Hi I have implemented Paypal Invoice, Express Checkout & Recurring Payments services using adaptive methods (NVP) call. It is working fine on my local system with sandbox account but not on development server and facing problem wherever I have called the paypal services based on request.
Code
InvoiceModelAlias.PaymentTermsType paymentTermsType = (InvoiceModelAlias.PaymentTermsType)Enum.Parse(typeof(InvoiceModelAlias.PaymentTermsType),invoice.PaymentTerms.ToUpper());
InvoiceModelAlias.CreateAndSendInvoiceRequest invoiceRequest = new InvoiceModelAlias.CreateAndSendInvoiceRequest();
invoiceRequest.requestEnvelope = new InvoiceModelAlias.RequestEnvelope();
invoiceRequest.requestEnvelope.errorLanguage = "en_US";
invoiceRequest.invoice = new InvoiceModelAlias.InvoiceType();
invoiceRequest.invoice.currencyCode = invoice.CurrencyCode;
invoiceRequest.invoice.merchantEmail = invoice.MerchantEmail;
invoiceRequest.invoice.payerEmail = invoice.PayerEmail;
invoiceRequest.invoice.paymentTerms = paymentTermsType;
invoiceRequest.invoice.itemList = new InvoiceModelAlias.InvoiceItemListType();
invoiceRequest.invoice.itemList.item = new List<InvoiceModelAlias.InvoiceItemType>();
invoiceRequest.invoice.itemList.item.Add(new InvoiceModelAlias.InvoiceItemType(invoice.ItemName, Convert.ToDecimal(invoice.ItemQuantity), Convert.ToDecimal(invoice.ItemAmount)));
InvoiceAlias.InvoiceService invoiceService;
InvoiceModelAlias.CreateAndSendInvoiceResponse invoiceResponse = null;
invoiceService = GetService();
invoiceResponse = invoiceService.CreateAndSendInvoice(invoiceRequest);
string ackRsponse = invoiceResponse.responseEnvelope.ack.ToString();
invoiceService.CreateAndSendInvoice(invoiceRequest)
Exception
PayPal.Exception.ConnectionException: Invalid HTTP response The underlying connection was closed: An unexpected error occurred on a receive.
at PayPal.HttpConnection.Execute(String payLoad, HttpWebRequest httpRequest)
at PayPal.APIService.MakeRequestUsing(IAPICallPreHandler apiCallHandler)
at PayPal.BasePayPalService.Call(IAPICallPreHandler apiCallHandler)
at PayPal.Invoice.InvoiceService.CreateAndSendInvoice(CreateAndSendInvoiceRequest createAndSendInvoiceRequest, String apiUserName)
at PayPal.Invoice.InvoiceService.CreateAndSendInvoice(CreateAndSendInvoiceRequest createAndSendInvoiceRequest)
at DoPayments.Payments.Invoices.CreateAndSendInvoice(Invoice invoice)
Will you please someone help me to get this out or suggest whats the reason behind this as it is working fine at local but not on development/production server.
Same kind of issue I am facing in case of express checkout and recurring payment methods too which is below:
com.paypal.sdk.exceptions.FatalException: The underlying connection was closed: An unexpected error occurred on a receive.
at com.paypal.sdk.core.nvp.NVPAPICaller.Call(String NvpRequest)
at com.paypal.sdk.services.NVPCallerServices.Call(String requestnvp)
Thanks in advance.

Resources