LYNX SDK

Lynx mobile supports 2 api's. Built in lynxMobile SDK described below and Scatter by way of the new ScatterLynx plugin.

ScatterLynx Plugin

With the help of Nathan from Scatter we have now added support for scatterjs. So now by upgrading your scatter libraries to the latest you can import the ScatterLynx plugin! If you are going to use scatter you only need to import the needed plugins and then just keep doing whatever you've been doing with scatter. Below is a quickstart, but you can find more Scatter specific documentation here.


import ScatterJS from '@scatterjs/core';
import ScatterEOS from '@scatterjs/eosjs2'
import ScatterLynx from '@scatterjs/lynx'

ScatterJS.plugins( new ScatterEOS(), new ScatterLynx(Eos || {Api, JsonRpc}) );
                    

LYNX SDK

Below describes usage of the lynxMobile SDK. If you aren't using ScatterLynx plugin or want to also use functionality from lynxMobile, read on. The lynx sdk is the bridge to communicating with LYNX applications. Even ScatterLynx talks to LYNX by way of the LYNX SDK.


Basic Usage


// iOS
navigator.userAgent == "EOSLynx IOS"

// Android
navigator.userAgent == "EOSLynx Android"

// Desktop 2.0+
navigator.userAgent == "EOSLynx Desktop"
                    

Listen for lynxMobile sdk being added to window

iOS, Android, Desktop 2.0+

// will inject the lynxMobile SDK object 
// into the page.
// Your app will have access to the global lynxMobile 
// Add an event listner on window like below to be notified
// once the lynxMobile object has been added to window.
window.addEventListener("lynxMobileLoaded", function() {
    // lynx is on the window and ready!
});
    

Listen for Lynx App moving to background

iOS, Android

window.addEventListener("lynxMobileAppEnteredBackground", function() {
    // do stuff here like pause video or audio, etc
});
    

Listen for Lynx App coming back to foreground

iOS, Android

window.addEventListener("lynxMobileAppEnteredForeground", function() {
    // do stuff here like restart video or audio, etc
});
    

Request Full screen

iOS, Android

lynxMobile.requestFullscreen(true); // will hide top and bottom bars. This also will add a small floating menu to top right.
lynxMobile.requestFullscreen(false); // will restore top and bottom bars.

// Example of how to go full screen.
// listen for when lynxMobile is added to window
window.addEventListener("lynxMobileLoaded", function() {
    lynxMobile.requestFullscreen(true);
});
    

Request Landscape Orientation

iOS, Android

lynxMobile.requestLandscape(true); // will go to fullscreen if not currently and then auto rotate to landscapeRight
lynxMobile.requestLandscape(false); // will auto rotate to portait

// Example of how to go rotate to landscape.
// listen for when lynxMobile is added to window
window.addEventListener("lynxMobileLoaded", function() {
    lynxMobile.requestLandscape(true);
});
    

Request Set Account Name

iOS, Android, Desktop 2.0+
// Use await to return a promise
(async () => {

    let result;

    try {
        result = await window.lynxMobile.requestSetAccountName();
    } catch (err) {
        console.log(err);
    }

    console.log(result); // "funstuffgogo" 12 character account name returned here

})();

Request Set Account

iOS, Android, Desktop 2.0+
// Use await to return a promise
(async () => {

    let result;

    try {
        result = await window.lynxMobile.requestSetAccount("sessionId123");
    } catch (err) {
        console.log(err);
    }

    console.log(result);

})();

// result
/* 
{
"account": Object,
"chainId": String,
"tokens": [
    {
        "symbol": "EOS",
        "balance": "2.0436 EOS",
        "contract": "eosio.token",
        "precision": 4
    },
    {
        "symbol": "EETH",
        "balance": "10000.0000 EETH",
        "contract": "ethsidechain",
        "precision": 4
    },
    {
        "symbol": "PUB",
        "balance": "4846.8660 PUB",
        "contract": "publytoken11",
        "precision": 4
    },
    {
        "symbol": "EDNA",
        "balance": "0.0000 EDNA",
        "contract": "ednazztokens",
        "precision": 4
    }
],
"version": "1.4.4",
"session": "Zeyo6L7VVlC2"
}
*/

Transfer

iOS, Android, Desktop 2.0+
// Use await to return a promise
(async () => {

    let result;

    try {
        result = await window.lynxMobile.transfer({ 
            contract: "therealkarma", symbol: "KARMA", 
            toAccount: "funstuffgogo", amount: "0.0001", memo: "Hello there"
        });
    } catch (err) {
        console.log(err);
    }

    console.log(result); // {transaction_id: "3a50d9a4bda0a8e2a4c23526da15369345bd61c72d37d844365f4bfee5c18fcb", processed: Object}

})();

Transact

iOS, Android, Desktop 2.0+
// Use await to return a promise
let transaction = {
    actions: [{
        account: "eosio",
        name: "delegatebw",
        data: {
            from: "funstuffgogo",
            receiver: "funstuffgogo",
            transfer: false,
            stake_cpu_quantity: "0.0005 EOS",
            stake_net_quantity: "0.0000 EOS"
        },
        authorization: [
            {
                actor: "funstuffgogo",
                permission: "active"
            }
        ]
    },
    {
        account: "eosio",
        name: "undelegatebw",
        data: {
            from: "funstuffgogo",
            receiver: "funstuffgogo",
            unstake_cpu_quantity: "0.0000 EOS",
            unstake_net_quantity: "0.0003 EOS"
        },
        authorization: [
            {
                actor: "funstuffgogo",
                permission: "active"
            }
        ]
    }]
}

(async () => {

    let result;

    try {
        result = await window.lynxMobile.transact(transaction);
    } catch (err) {
        console.log(err);
    }

    console.log(result); // {transaction_id: "3a50d9a4bda0a8e2a4c23526da15369345bd61c72d37d844365f4bfee5c18fcb", processed: Object}

})();

Request Transaction Signature for Current Account

iOS, Android, Desktop 2.0+
// Use await to return a promise
let transaction = {
   "expiration": "2019-01-13T18:56:47.000",
   "ref_block_num": 35719,
   "ref_block_prefix": 3947404337,
   "max_net_usage_words": 0,
   "max_cpu_usage_ms": 0,
   "delay_sec": 0,
   "context_free_actions": [],
   "actions": [
      {
         "account": "eosio.token",
         "name": "transfer",
         "authorization": [
            {
               "actor": "funstuffgogo",
               "permission": "active"
            }
         ],
         "data": {
            "from": "funstuffgogo",
            "to": "safetransfer",
            "quantity": "0.0001 EOS",
            "memo": "funstuffgogo"
         }
      }
   ],
   "transaction_extensions": []
}

(async () => {

    let result;

    try {
        result = await window.lynxMobile.requestSignature(transaction);
    } catch (err) {
        console.log(err);
    }

    console.log(result); // { serializedTransaction: "3a50d9a4b....", signatures: [SIG_K1_asdflkjasdf.....] }

})();

Request Arbitrary Signature for Current Account

iOS, Android, Desktop 2.0+
// Use await to return a promise
(async () => {

    let result;

    try {
        result = await window.lynxMobile.requestArbitrarySignature({
            data: "the string you wish to sign",
            whatFor: "The reason you want the signature. This will displayed to the user."
        });
    } catch (err) {
        console.log(err);
    }

    console.log(result); // "SIG_K1_JvbGYMSe7auMt8TvLUkoi1A1ywdqoNMmZ4vSeMfaFFtLL58eRGBtzk8HqbmyyrGWTUvhmFAQFHoMeF4icHrtwJQAqynqcD"

})();