Solana: How to get token CA when subscribing to websockets for newly minted coins

Submit token Ca with freshly dug coins using web

As a creator, you will probably be interested in learning to subscribe to Websockt events for coins, fresh Solana. In this article, we will investigate the opportunity to get token CA (contract address) when a new access key is called from Websockt API.

Context:

We have a specific context where we want to create API Solana: Subscription Subscription, which returns the freshly excavated currency list. We also need to get the address of each currency agreement in the answer.

Structure of Websockt API event:

When you subscribe to the WebSockt event using API Solana: Subscribe, you will receive a notification structure with multiple fields:

Json

{

“EVENSIGNATURE”: Circuit,

"Slot": Number,

"Worth": {

...

outdoor names and values ​​...

}

}

Token Ca Recovery:

Usually, the token CA is a direction of a contract that has created a new currency. When a new token summoned from Websocket API, it will include CA in its messages structure.

To restore the token CA, you need to analyze the notification structure and extract the field value "C".

Example of solution:

Here is an example solution using Typescript:

Tygiukas

Import {WebsocketClient} Solana-Websochet-Api;

CONST CLIENT = NEW WEBSOCKETCLIENT ({{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{

URL: "

});

Function async getnewlymindcoins () {)

CONST = ALEA Customer.

Meanwhile (true) {

Constate Message = alea subscription.waitformessage ({{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{) -

Waiting time: 1000,

});

IF (! Message) breaks;

// Analyze the notification structure to pull out the CA field value

Consa cafield = Message.Value;

Consta caaddress = cafield.ca.costin ();

Console.log (Ca freshly mined coins address $ {caaddress});

}

}

`

*. The notification structure also contains the number and value of the object socket.

In conclusion, you can restore the newly attached coins Conok C by analyzing the Solana Analysis of the Message Structure of Websockt API. This solution provides a fragment of the code to start.

Leave a Reply

Your email address will not be published. Required fields are marked *

X