I just started learning ethers, here is my code:
(async () => {
const connection = new ethers.providers.JsonRpcProvider(
"https://mainnet.infura.io/v3/key"
);
const contract = new ethers.Contract(
"0x7be8076f4ea4a4ad08075c2508e481d6c946d12b",
abi,
connection
);
contract.on("atomicMatch_", (...args) => {
console.log(args);
});
})();
so the contract is opensea main contract - link
I would like to listen to sales transactions/events. As I see in the contract name of that event is probably Atomic Match_ or atomicMatch_ in ABI.
For ABI I just copy pasted whole contract to https://remix.ethereum.org/ website and copied abi code. The problem is I am getting this error now:
Error: no matching event (argument="name", value="atomicMatch_", code=INVALID_ARGUMENT, version=abi/5.5.0)
What is wrong here? I tried both names of event but I get the same error over and over...
#edit here is sandbox for it,
what is weird when I change event name to OrdersMatched for example it works totally fine...
Ethers contract.on() (docs) is invoked when an event with the specified name is emitted.
Your snippet is passing a function name (atomicMatch_), not an event name.
The atomicMatch_ function effectively emits the event named OrdersMatched. That's why changing the handler to contract.on('OrdersMatched') fixes the issue.
Also, the sandbox is using a built-in provider under the getDefaultProvider(), which is communicating with the app over WSS. Your snippet is using a HTTPS provider that is by design unable to listen to events. You'll need to use a WSS provider as well (they are supported by Infura).
Related
This error has prevented me from using cypress for months now 😟
/// <reference types="cypress" />
describe('User login', () => {
beforeEach(() => {
cy.visit('http://localhost:8080')
})
// ...
})
i'm getting an error that says:
(uncaught exception)TypeError: Failed to set an indexed property on 'DOMStringList': Indexed property setter is not supported.
More details:
app specs:
react 16.14.0
react-router-dom 4.3.1
react-redux ^5.0.4"
it seems the error is from something loading (assuming webpack)
GET 200 /sockjs-node/info?t=1672024046431
I notice if i comment out a specific component (the header bar) that the rest of the app seems to load
When you see (uncaught exception) it's generally your app that is causing it.
You cannot change anything in the test code to actually fix it, which is pretty obvious since your test does not do anything except visit the page.
You can make Cypress turn a blind eye to this particular error by catching the fail event and returning false from inside the handler - that tells Cypress to carry on as if the error did not occur.
But now this is likely to be trouble later on, since it looks like the step is in authorization and you won't get very far without that.
The event catcher should be at the top of the spec and is this code:
Cypress.once('uncaught:exception', () => false)
If you find this is all that's needed, and you can test authorize correctly after that, then keep the code permanently but add a check for the specific error message
Cypress.once('uncaught:exception', (err) => {
if (err.message.contains('Failed to set an indexed property')) {
return false
}
})
But if you continue to get errors after this, I'm afraid you will have to post the React code to get a better answer.
We are having a session-enabled azure bus topic. This topic can have multiple messages with distinct session IDs. We want to create a listener/receiver that keeps reading messages from the Topic. As we have multiple dynamic session IDs, we can not use acceptSession to create a handler. We have tried using the methods createReceiver and acceptNextSession methods of ServiceBusClient but they have the following issues
CreateReceiver: This method does not work on session-enabled subscriptions giving a runtime error.
acceptNextSession: This method only listens to the first message and does not read further messages.
Our Current code is :
const serviceBusSettings = this.appSettings.Settings.serviceBus;
const sbClient = new ServiceBusClient(serviceBusSettings.connectionString);
//const receiver = sbClient.createReciver(topicName, subscriptionName);
const receiver = sbClient.acceptNextSession(topicName, subscriptionName);
const handleTopicError = async (error: any) => {
this.logger.error(error);
throw error;
};
(await receiver).subscribe({
processMessage: handleTopicMessage, // handleTopicMessage is a method passed as an argument to the function where this code snippet exists
processError: handleTopicError
});
We also tried implementation one of the sample code repo wiki. But the methods shared in the example seems to be no longer available in new npm version of #azure/service-bus Link to tried example
Can anyone suggest some solution to this?
There's a sample showing how you can continually read through all the available sessions. Could you please check to see if it is helpful?
https://github.com/Azure/azure-sdk-for-js/blob/21ff34e2589f255e8ffa7f7d5d65ca40434ec34d/sdk/servicebus/service-bus/samples/v7/javascript/advanced/sessionRoundRobin.js
I am trying to follow a basic Web Audio API tutorial from MDN, except I'm using TypesScript and React (made with create-react-app) instead of vanilla JS. Since I'm in React, I'm using the useRef hook to reference the audio element in my jsx, instead of document.querySelector() like in the tutorial. Here is the problematic code:
const audioContext = new AudioContext();
const audioRef = useRef<HTMLMediaElement>(null);
const track = audioContext.createMediaElementSource(audioRef.current);
Gives a TS error under audioRef.current that
Argument of type 'HTMLMediaElement | null' is not assignable to parameter of type 'HTMLMediaElement'.
I tried casting audioRef.current as an HTMLMediaElement like this:
const track = audioContext.createMediaElementSource(audioRef.current as HTMLMediaElement);
This gets rid of the error in my editor, but then the code fails in the browser; this is the error I get there:
TypeError: Failed to execute 'createMediaElementSource' on 'AudioContext': parameter 1 is not of type 'HTMLMediaElement'.
I also tried defining the audioRef variable as an HTMLAudioElement instead of an HTMLMediaElement like so: const audioRef = useRef<HTMLAudioElement>(null); but that doesn't fix anything.
I should also note that I tried this in a plain TS file and get the same errors there. So I don't think the problem is related to use of the useRef hook.
Is there someway to get this to work? I'm worried that the Type definitions just aren't matching up with the functionality of the Web Audio API.
I realized the problem: createMediaElementSource was being called with audioRef.current which was null at the time of execution. Whoops.
I'm adding Raygun.io APM to our Angular 8 app with Angular Universal.
It is known that raygun.io has a client side javascript library and to add this to a Angular with Universal, DOM window API must be created. This can be done using domino npm using this code below:
There is also an installation guide for Angular via npm called raygun4js however the problem still exists.
// Domino for defining Windows API in SSR
(found # https://www.npmjs.com/package/domino )
const domino = require('domino');
const fs = require('fs');
const path = require('path');
const template = fs.readFileSync(index.html).toString();
const win = domino.createWindow(template);
global['window'] = win; // will be used for NodeJS to read Window API
global['document'] = win.document;
*domino creates a window api and sets it to a global called win.
After adding this line to an NPM project server.ts, build and run command - an exception is found:
Raygun.Utilities = raygunUtilityFactory(window, Raygun);
^
ReferenceError: raygunUtilityFactory is not defined
This roots that a raygunUtilityFactory function is not defined within window API. Looking inside raygun.js in Github
window.raygunUtilityFactory = function(window, Raygun) {
var rg = {
getUuid: function() {
function _p8(s) {
var p = (Math.random().toString(16) + '000000000').substr(2, 8);
return s ? '-' + p.substr(0, 4) + '-' + p.substr(4, 4) : p;
}
// more code.....
Question is, how can NodeJS read raygunUtilityFactory function during build if it can't find it in window API?
UPDATE: I tried to do this on a smaller project but it seems that even its document for installing raygun.io doesn't include procedures for Angular Universal. It basically can't detect window API using domino
Raygun.Utilities = raygunUtilityFactory(window, Raygun);
^
ReferenceError: raygunUtilityFactory is not defined
Answer: Setting Raygun js as a global object and referencing it to a declared variable inside a service.
Reference: https://hackernoon.com/how-to-use-javascript-libraries-in-angular-2-apps-ff274ba601af
declare var rg4js: any;
*place this inside your service or your main component ts.
<script type="text/javascript">
!function(a,b,c,d,e,f,g,h){a.RaygunObject=e,a[e]=a[e]||function(){
(a[e].o=a[e].o||[]).push(arguments)},f=b.createElement(c),g=b.getElementsByTagName(c)[0],
f.async=1,f.src=d,g.parentNode.insertBefore(f,g),h=a.onerror,a.onerror=function(b,c,d,f,g){
h&&h(b,c,d,f,g),g||(g=new Error(b)),a[e].q=a[e].q||[],a[e].q.push({
e:g})}}(window,document,"script","//cdn.raygun.io/raygun4js/raygun.min.js","rg4js");
</script>
*add this to your index.html or download and add it to your project.
Do take note that the raygun script should be referenced as rg4js.
Angular will automatically know that the rg4js inside your TS file is reference to your raygun script tag.
-- I'm now able to see the crash reporting and the pulse monitoring inside our client dashboard. However, I noticed that all client side errors logs are not caught. I'm still researching way to send these unhandled errors - starting with windows.onerror.
Good to hear you have figured out part of the solution!
AngularJS captures a lot of errors under the hood automatically and to properly capture errors you will need to register your own angular error handler and when the callback is fired you can use the Raygun4JS send method to send the message to Raygun.
export class RaygunErrorHandler implements ErrorHandler {
handleError(e: any) {
rg4js('send', {
error: e,
});
}
}
Raygun has a little bit of angular documentation but can't import raygun4js via npm for Angular Universal (as per your discovery) so you will need to modify the examples shown. That said they should provide a good starting point.
I am trying to use stripe for the payment solution for my client.
here is the example code strait from documentation im trying to use:
var stripe = require("stripe")("sk_test_uTzXlltbjYmk6FISYoooBvFo");
stripe.accounts.retrieve(
"acct_1DEnU3AqtajnnBvl",
function(err, account) {
// asynchronously called
}
);
when I try to do error handling the err param is of type any, and I cant find out how to log what error is actually occurring. jumping to def doesn't seem to work either. I just want to see what my error is.
Here is link to docs:
https://stripe.com/docs/api?lang=node#create_account
According to the typings, the callbacks are of type IResponseFn<R>, which takes an error parameter of type IStripeError.
If you have #types/stripe installed and import the Stripe API using import, TypeScript should be able to tell you this. In this case, you should use the special import-assignment syntax for modules with a CommonJS-style export assignment:
import stripeFactory = require("stripe");
var stripe = stripeFactory("sk_test_uTzXlltbjYmk6FISYoooBvFo");
If you have the esModuleInterop compiler option enabled, the following should also work:
import stripeFactory from "stripe";
var stripe = stripeFactory("sk_test_uTzXlltbjYmk6FISYoooBvFo");
Let me know if it doesn't work.