LYNX SDK
Below describes usage of the lynxMobile SDK. The lynx sdk is the bridge to communicating with LYNX applications.
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, Desktop 2.0+
window.addEventListener("lynxMobileEnteredBackground", function() {
// do stuff here like pause video or audio, etc
});
Listen for Lynx App coming back to foreground
iOS, Android, Desktop 2.0+
window.addEventListener("lynxMobileEnteredForeground", 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+This method returns a cached value for the tokens. If you need to retrieve up to date token balances, please query the chain from your app directly.
// 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"
})();