Using Smart Contract

Sending Notifications from a Smart Contract via Neo Cast Contracts

Neo Cast contracts are designed to facilitate communication between smart contracts and wallet addresses (web3 users). Here's how you can send notifications from a smart contract using Neo Cast Contracts:

Prerequisites:

  1. Know the contract address of the Neo Cast Communication smart contract for the blockchain and network from which you are sending notifications. For example, the Staging Ethereum contract address is 0x87da9Af1899ad477C67FeA31ce89c1d2435c77DC, and the Staging Polygon contract address is 0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa. You can find a list of all smart contracts and their environments here.

  2. Ensure your channel is set up and running. Note down your channel address, which you will need to include in the code.

Steps to Send Notifications from a Smart Contract:

Step 1: Import the Neo Cast Comm Contract Interface:

// Neo Cast Comm Contract 
```java
public static void sendNotification(String topicId, String name, String description, String mediaUrl,
            String websiteUrl) 
```

Step 2: Call the sendNotification Function:

INeoCastCommInterface(EPNS_COMM_CONTRACT_ADDRESS_FOR_SPECIFIC_BLOCKCHAIN).sendNotification(
    YOUR_CHANNEL_ADDRESS, // The channel address; recommended to set the channel via the dApp and put its value here
    to, // The recipient's address; put address(this) for broadcast or subset, for targeted notifications, put the recipient's address
    bytes(
        string(
            // Here, you are passing the notification identity, segregator, payload type, segregator, notification title, segregator, and notification body
            abi.encodePacked(
                "0", // Notification identity; see documentation for details
                "+", // Segregator
                "3", // Payload type (1, 3, or 4 for Broadcast, targeted, or subset)
                "+", // Segregator
                "Title", // Notification title
                "+", // Segregator
                "Body" // Notification body
            )
        )
    )
);

Step 3: Add Smart Contract Address as a Delegate:

  • Lastly, go back to your channel and add the smart contract address as a delegate. This step ensures that notifications sent by your smart contract are routed through your channel and presented to your users.

By following these steps, you can use Neo Cast Contracts to enable your smart contract to send notifications to wallet addresses (web3 users), enhancing communication within the blockchain ecosystem.

Last updated