1.3.2 • Published 6 months ago

favorlet.js v1.3.2

Weekly downloads
-
License
-
Repository
-
Last release
6 months ago

favorlet.js

Favoret app to app SDK

Table of Contents

Features

  • Connect favorlet application

Installing

Using npm:

$ npm install favorlet.js

Using yarn:

$ yarn add favorlet.js

Using pnpm:

$ pnpm add favorlet.js

Using jsDelivr CDN:

<script src="https://cdn.jsdelivr.net/npm/favorlet.js"></script>

Using unpkg CDN:

<script src="https://unpkg.com/favorlet.js"></script>

Import

CommonJS

  const favorlet = require('favorlet.js');

ESM

  import favorlet from 'favorlet.js';

Request function

Preparation for making a request to Favorlet.

Connect wallet

const result = await favorlet.Request.connectWallet({
  appName: 'Test app',
  chainId: 8217,
  successAppLink: 'app://testapp/success', // optional data
  failAppLink: 'app://testapp/fail', // optional data
});

Sign message

const result = await favorlet.Request.signMessage({
  appName: 'Test app',
  chainId: 8217,
  successAppLink: 'app://testapp/success', // optional data
  failAppLink: 'app://testapp/fail', // optional data
  from: "0xd464B499639A267Da03721b2DBa7469896732947",
  message: "Hi! This is a test message.",
});

Execute contract

const result = await favorlet.Request.executeContract({
  appName: 'Test app',
  chainId: 8217,
  successAppLink: 'app://testapp/success', // optional data
  failAppLink: 'app://testapp/fail', // optional data
  transactions: [
    {
      from: '0xd464B499639A267Da03721b2DBa7469896732947',
      to: '0xd464B499639A267Da03721b2DBa7469896732947',
      abi: '[{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"}]',
      functionName: 'transferFrom',
      params: '["0xd464B499639A267Da03721b2DBa7469896732947","0xe13F97c9b97BC41BF2540fc2e8CA6998439100AB","13"]',
      value: '0' // peb or wei
    }
  ]
});

Send standard coin(klay, ether)

  const result = await favorlet.Request.sendCoin({
    appName: 'Test app',
    chainId: 8217,
    successAppLink: 'app://testapp/success', // optional data
    failAppLink: 'app://testapp/fail', // optional data
    transactions: [
      {
        from: '0xd464B499639A267Da03721b2DBa7469896732947',
        to: '0xd464B499639A267Da03721b2DBa7469896732947',
        value: '10000000000000000000' // peb or wei
      }
    ]
  });

Result(common)

{
  "requestId": "97a770b9-6701-4304-ae0a-29e41c61d32a",
  "expiredAt": 1664939293
}

Receipt function

Steps to check if the request was successful. Periodically check for changes in the 'requested' phase.

Get receipt

const receipt = await favorlet.receipt('544ca84d-d4e8-4807-a3e8-a2b8cd2b51fa');

Connect wallet receipt

// requested: Status requested by Favorlet
{
  "requestId": "bb0edb1e-ee50-4b11-9f7b-0fb3f24fb646",
  "expiredAt": 1664949251,
  "connectWallet": {
    "status": "requested"
  }
}
// succeed: Favorlet processed successfully
{
  "requestId": "bb0edb1e-ee50-4b11-9f7b-0fb3f24fb646",
  "expiredAt": 1664949251,
  "connectWallet": {
    "status": "succeed",
    "address": "0xe13F97c9b97BC41BF2540fc2e8CA6998439100AB"
  }
}

// canceled: Request canceled by user
{
  "requestId": "bb0edb1e-ee50-4b11-9f7b-0fb3f24fb646",
  "expiredAt": 1664949251,
  "connectWallet": {
    "status": "canceled"
  }
}

Sign message receipt

// requested: Status requested by Favorlet
{
  "requestId": "bb0edb1e-ee50-4b11-9f7b-0fb3f24fb646",
  "expiredAt": 1664949251,
  "signMessage": {
    "status": "requested"
  }
}
// succeed: Favorlet processed successfully
{
  "requestId": "bb0edb1e-ee50-4b11-9f7b-0fb3f24fb646",
  "expiredAt": 1664949251,
  "signMessage": {
    "status": "succeed",
    "signature": "0x5d091a1c59b92a15e19ec08929dc9ca67061cd1348f504257c1d16da778f516b4dd5a31ea5bb8b293cbb396f56ef258cd5102b79a60e32563f68601385702ff61c"
  }
}
// canceled: Request canceled by user
{
  "requestId": "bb0edb1e-ee50-4b11-9f7b-0fb3f24fb646",
  "expiredAt": 1664949251,
  "signMessage": {
    "status": "canceled"
  }
}

Execute Contract receipt

// requested: Status requested by Favorlet
{
  "requestId": "bb0edb1e-ee50-4b11-9f7b-0fb3f24fb646",
  "expiredAt": 1664949251,
  "transactions": [
    { "status": "requested" }
  ]
}
// excuted: Sending transaction to blockchain
{
  "requestId": "bb0edb1e-ee50-4b11-9f7b-0fb3f24fb646",
  "expiredAt": 1664949251,
  "transactions": [
    { "status": "excuted" }
  ]
}
// succeed: Favorlet processed successfully.
{
  "requestId": "bb0edb1e-ee50-4b11-9f7b-0fb3f24fb646",
  "expiredAt": 1664949251,
  "transactions": [
    {
      "status": "succeed",
      "txHash": "0x8f4e16bfe0c21c3cd20650110b8614e585d950d9b931b515b11575d08590a6e2"
    }
  ]
}

// failed: There is a problem with the value or the blockchain transaction has failed.
{
  "requestId": "bb0edb1e-ee50-4b11-9f7b-0fb3f24fb646",
  "expiredAt": 1664949251,
  "transactions": [
    {
      "status": "failed",
      "txHash": "0x8f4e16bfe0c21c3cd20650110b8614e585d950d9b931b515b11575d08590a6e2", // optional data
      "errorMessage": "execution reverted : invalid id"
    }
  ]
}
// canceled: Request canceled by user
{
  "requestId": "bb0edb1e-ee50-4b11-9f7b-0fb3f24fb646",
  "expiredAt": 1664949251,
  "transactions": [
    { "status": "canceled" }
  ]
}
// Multiple states in a transaction.
{
  "requestId": "bb0edb1e-ee50-4b11-9f7b-0fb3f24fb646",
  "expiredAt": 1664949251,
  "transactions": [
    {
      "status": "succeed",
      "txHash": "0x8f4e16bfe0c21c3cd20650110b8614e585d950d9b931b515b11575d08590a6e2"
    },
        {
      "status": "failed",
      "txHash": "0x8f4e16bfe0c21c3cd20650110b8614e585d950d9b931b515b11575d08590a6e2", // optional data
      "errorMessage": "execution reverted : invalid id"
    },
    { "status": "excuted" }
  ]
}

Send coin receipt

// requested: Status requested by Favorlet
{
  "requestId": "bb0edb1e-ee50-4b11-9f7b-0fb3f24fb646",
  "expiredAt": 1664949251,
  "transactions": [
    { "status": "requested" }
  ]
}
// excuted: Sending transaction to blockchain
{
  "requestId": "bb0edb1e-ee50-4b11-9f7b-0fb3f24fb646",
  "expiredAt": 1664949251,
  "transactions": [
    { "status": "excuted" }
  ]
}
// succeed: Favorlet processed successfully.
{
  "requestId": "bb0edb1e-ee50-4b11-9f7b-0fb3f24fb646",
  "expiredAt": 1664949251,
  "transactions": [
    {
      "status": "succeed",
      "txHash": "0x8f4e16bfe0c21c3cd20650110b8614e585d950d9b931b515b11575d08590a6e2"
    }
  ]
}
// failed: There is a problem with the value or the blockchain transaction has failed.
{
  "requestId": "bb0edb1e-ee50-4b11-9f7b-0fb3f24fb646",
  "expiredAt": 1664949251,
  "transactions": [
    {
      "status": "failed",
      "txHash": "0x8f4e16bfe0c21c3cd20650110b8614e585d950d9b931b515b11575d08590a6e2", // optional data
      "errorMessage": "execution reverted : invalid id"
    }
  ]
}

// canceled: Request canceled by user
{
  "requestId": "bb0edb1e-ee50-4b11-9f7b-0fb3f24fb646",
  "expiredAt": 1664949251,
  "transactions": [
    { "status": "canceled" }
  ]
}

// Multiple states in a transaction.
{
  "requestId": "bb0edb1e-ee50-4b11-9f7b-0fb3f24fb646",
  "expiredAt": 1664949251,
  "transactions": [
    {
      "status": "succeed",
      "txHash": "0x8f4e16bfe0c21c3cd20650110b8614e585d950d9b931b515b11575d08590a6e2"
    },
        {
      "status": "failed",
      "txHash": "0x8f4e16bfe0c21c3cd20650110b8614e585d950d9b931b515b11575d08590a6e2", // optional data
      "errorMessage": "more value than your balance"
    },
    { "status": "excuted" }
  ]
}
1.3.2

6 months ago

1.3.1

6 months ago

1.3.0

6 months ago

1.2.7

10 months ago

1.2.6

10 months ago

1.2.5

10 months ago

1.2.0

1 year ago

1.2.4

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago