Eternals
  • Introduction
  • Eternia
    • Lore
    • Creatures System
      • Legend
      • Elementals
        • Fire
        • Nature
        • Earth
        • Water
        • Metal
      • Base Eternals
    • Space Stone
  • Alliance Mining Program
    • Getting Started
    • User Profile (Alliance Center)
      • Upgrade Account
      • Achievements
    • Mechanism
    • Reward Distribution
  • $ETNS (Eternals Stars Program)
    • The $ETNS System
  • Eternals Core
    • Eternals House
      • Mood
      • How to maintain a good pet's mood?
      • Decoration
      • Shop
    • Eternals Space
      • Missions
      • Mining Tower
      • Leaderboard
      • Refill Plasma
  • Eternals World
    • Gomoku
      • Game modes: Classic and Eternians
      • Battle Deck
      • Quick Match
      • Ranking Match
      • How to earn Tickets
      • How to join Eternals Gomoku
      • Missions
      • Daily Login
      • Mastery Points
      • Win Streak
      • Pet Skills
      • Leaderboard and Reward Pools
  • ETER Token
  • How To Earn With Eternals?
  • Official Links
    • Website
    • Twitter
    • Discord
    • App Store
    • Google Play
  • GDK Documentation
    • Ninety Eight Game Development Kit
    • Introduction
    • Unity
      • GDK Installation Guide
      • Update Guide
      • Examples
      • Downloads
      • Release Notes
      • API Reference
        • v1.0.0
          • NinetyEight.INEGdk
          • NinetyEight.ErrorCode
          • NinetyEight.NEGameProfile
          • NinetyEight.NEGameProfileCallback
          • NinetyEight.NEGameProfileResponse
          • NinetyEight.NEGdkConfig
          • NinetyEight.NEInitCallback
          • NinetyEight.NELoginCallback
          • NinetyEight.NELoginData
          • NinetyEight.NEProvider
          • NinetyEight.NEShopBuyCallback
          • NinetyEight.NEShopBuyResponse
          • NinetyEight.NEShopInfoCallback
          • NinetyEight.NEShopInfoResponse
          • NinetyEight.NEShopItem
          • NinetyEight.NEShopPack
          • NinetyEight.NEUserBalance
          • NinetyEight.NEUserBalanceCallback
          • NinetyEight.NEUserBalanceResponse
          • NinetyEight.NEUserPet
          • NinetyEight.NEUserPetCallback
          • NinetyEight.NEUserPetResponse
          • NinetyEight
    • Cocos Creator
      • Installation Guide
      • Update Guide
      • Examples
      • Downloads
      • Release Notes
      • API Reference
        • NinetyEight Game Development Kit - Cocos Creator
          • Enumerations
            • NinetyEight.NEEnvironment
            • NinetyEight.NEErrorCode
            • NinetyEight.NEProvider
          • Interfaces
          • Type-aliases
            • NEGameProfile
            • NEGameProfileCallback
            • NEGameProfileResponse
            • NEGdkConfig
            • NEInitCallback
            • NELoginCallback
            • NELoginData
            • NEShopBuyCallback
            • NEShopBuyResponse
            • NEShopInfoCallback
            • NEShopInfoResponse
            • NEShopItem
            • NEShopPack
            • NEUserBalance
            • NEUserBalanceCallback
            • NEUserBalanceResponse
            • NEUserPet
            • NEUserPetCallback
            • NEUserPetResponse
  • LEGAL
    • Game Terms of Use
    • Privacy Policy
    • Terms of Use
Powered by GitBook
On this page
  • Cocos Creator GDK Examples
  • Initialize the GDK
  • Login
  • Get User Pets Data
  • Get User Balances Data
  • Get Shop Data
  • Buy a Pack in Shop
  1. GDK Documentation
  2. Cocos Creator

Examples

Cocos Creator GDK Examples

You can check outthe example code in the package at negdk/assets/negdk/sample/NEGdkSample.ts

Initialize the GDK

export class ExampleInit extends Component {
    protected onLoad(): void {
        const config: NEGdkConfig = {
            gameKey: "eternal",
            platformSource: "ETERNAL",
            ramperAppId: "vgzjondflu",
            scheme: "negdkcc",
            subPlatform: "",
            environment: NEEnvironment.DEV,
            loginCacheEnabled: true
        }
        NEGdk.getInstance().initialize(config, (errorCode) => {
            const success = errorCode === NEErrorCode.SUCCESS;
            if (success) {
                conslose.log("GDK initialize successfully!");
            } else {
                conslose.error(`GDK initialize failed, errorCode = ${errorCode}`);
                // Check if already login in case you are using login cache
                if (negdk.isLoggedIn()) {
                    // already login 
                } else {
                    // not login yet
                }
            }
        });
    }
}

Login

Social Login

export class ExampleSocialLogin extends Component {

    private loginWithGoogle() {
        NEGdk.getInstance().loginWithGoogle(this.onLoginCompleted.bind(this));
    }

    private loginWithFacebook() {
        NEGdk.getInstance().loginWithFacebook(this.onLoginCompleted.bind(this));
    }

    private loginWithEmail() {
        NEGdk.getInstance().loginWithEmail(this.onLoginCompleted.bind(this));
    }

    private loginWithTelegram() {
        NEGdk.getInstance().loginWithTelegram(this.onLoginCompleted.bind(this));
    }

    private loginWithApple() {
        NEGdk.getInstance().loginWithApple(this.onLoginCompleted.bind(this));
    }

    private onLoginCompleted(errorCode: number, data: NELoginData) {
        const success = errorCode === NEErrorCode.SUCCESS;
        if (success) {
            console.log(`Login success, authen token: ${data.authToken}`});
        } else {
            console.log(`Login failed, errorCode: ${errorCode}`});
        }
    }
}

Create/Restore Wallet

export class ExampleWalletLogin extends Component {

    private createWalletAndLogin(): string {
        // Create a new wallet
        const phrase = NEGdk.getInstance().createWallet();

        // Login with new wallet
        NEGdk.getInstance().loginWithPhrase(phrase, this.onLoginCompleted.bind(this));
    }

    private restoreWallet() {
        // Allow user to enter seedphrase
        const phrase = this.editBoxPhrase.string;

        // Restore wallet and login
        NEGdk.getInstance().loginWithPhrase(phrase, this.onLoginCompleted.bind(this));
    }

    private onLoginCompleted(errorCode: number, data: NELoginData) {
        const success = errorCode === NEErrorCode.SUCCESS;
        if (success) {
            console.log(`Login success, authen token: ${data.authToken}`});
        } else {
            console.log(`Login failed, errorCode: ${errorCode}`});
        }
    }
}

Get User Pets Data

export class ExampleUserPets extends Component {
    private requestUserPets() {
        NEGdk.getInstance().requestUserPets((response) => {
            if (!response.errorCode) {
                var pets = response.data; // get user pets data from response
            } else {
                // error handling
            }
        });
    }
}

Get User Balances Data

export class ExampleUserBalances extends Component {
    private requestUserBalances() {
        NEGdk.getInstance().requestUserBalances((response,) => {
            if (!response.errorCode) {
                var balances = response.data; // get user balances data from response
            } else {
                // error handling
            }
        });
    }
}

Get Shop Data

export class ExampleShop extends Component {
    private requestShopInfo() {
        NEGdk.getInstance().requestShopInfo((response) => {
            if (!response.errorCode) {
                var shopPacks = response.data; // get shop packs data from response
            } else {
                // error handling
            }
        });
    }
}

Buy a Pack in Shop

export class ExampleShopBuy extends Component {
    private buyShopPack() {
        var packId = 26;
        var amount = 1;
        var currency = "SPACE_STONE";
        NEGdk.getInstance().buyShopPack(packId, amount, currency, (response) => {
            if (!response.errorCode) {
                var remainBalance = response.data; // user balance for the currency after purchase
            } else {
                // Failed to buy the pack!!!
            }
        });
    }
}
PreviousUpdate GuideNextDownloads

Last updated 21 days ago