Execute Contract

1. Request.executeContract

Parameters

Name
Type
Description

chainId

number

Chain ID of the particular network

appName

string

Name that will appear when running the contract

transactions

object array

Information needed to run the contract (see below for details)

transactions 객체는 다음을 포함합니다.

Name
Type
Description

from

string

Wallet address to call the transaction

to

string

Called contract address

value

string

(optional) Platform coin transfer when calling abi function is payable

abi

string

abi for generating transactions

params

string

Parameters of the abi function to generate a transaction

functionName

string

The name of the function you want to call on abi

Response

Name
Type
Description

requestId

string

ID to track the operation or transaction request

appName

number

The amount of time (in seconds) that an operation or transaction request expires.

Example

TRANSFER_ABI.json
// TRANSFER_ABI.json (테스트 파일)
[
  {
    "inputs": [
      {
        "name": "_to",
        "type": "address"
      },
      {
        "name": "_value",
        "type": "uint256"
      }
    ],
    "outputs": [
      {
        "name": "",
        "type": "bool"
      }
    ],
    "name": "transfer",
    "payable": false,
    "stateMutability": "nonpayable",
    "type": "function"
  }
]
import { Request } from "favorlet.js";

const response = await Request.executeContract({
  chainId: 8217, // 해당 체인 id
  appName: "BlockChainApp", // FAVORLET 앱에 노출
  transactions: [
    {
      from: "0x{address in hex}", // 트랜잭션을 호출할 지갑 주소
      to: "0x{address in hex}", // 호출되는 컨트랙트 주소
      value: "1000000000000000000", // 호출하는 abi 함수가 payable 인 경우 플랫폼 코인 전송
      abi: JSON.stringify(TRANSFER_ABI), // 트랜잭션을 발생시키기 위한 abi
      params: `["0x{address in hex}", 1]`, // 트랜잭션을 발생시키기 위한 abi 함수의 파라미터
      functionName: "transfer", // abi에서 호출 하려는 함수 이름
    },
  ],
});

console.log(response);
/*
{
  requestId: "4ee3ed57-b785-4196-9018-7b682c7a8048",
  expiredAt: 1667893310,
}
*/

Parameters

Type
Description

string

requestId received when requesting

Response

Type
Description

string

DeepLink to the request page in FAVORLET app

Example

import { createDeepLink } from "favorlet.js";

const deepLink = createDeepLink(response.requestId); // Request를 통해 받은 requestId

/*
- PC: 생성된 deepLink를 qrcode 라이브러리를 이용하여 QR 생성 후 스마트폰으로 스캔
- Mobile: window.location.href 등을 사용하여 생성된 deepLink로 직접 이동
*/
console.log(deepLink);
// https://app.favorlet.link/?requestId=4ee3ed57-b785-4196-9018-7b682c7a8048

3. receipt

import { receipt } from "favorlet.js";

const result = await receipt(response.requestId); // Request를 통해 받은 requestId

console.log(result);
/*
- status에 따라 이후 분기 처리

### requested
{
  requestId: "4ee3ed57-b785-4196-9018-7b682c7a8048",
  expiredAt: 1667893310,
  action: "executeContract",
  transactions: [
    { status: "requested" }
  ]
}

### executed
{
  requestId: "4ee3ed57-b785-4196-9018-7b682c7a8048",
  expiredAt: 1667893310,
  action: "executeContract",
  transactions: [
    { status: "executed" }
  ]
}

### canceled
{
  requestId: "4ee3ed57-b785-4196-9018-7b682c7a8048",
  expiredAt: 1667893310,
  action: "executeContract",
  transactions: [
    { 
      status: "canceled",
      txHash: null,
      errorMessage: null
    }
  ]
}

### failed
{
  requestId: "4ee3ed57-b785-4196-9018-7b682c7a8048",
  expiredAt: 1667893310,
  action: "executeContract",
  transactions: [
    { 
      status: "failed",
      txHash: "0x5a4e16cfe0c21c3cd20456340b8614f585d951d9b931b515b11575d08142a6e2",
      errorMessage: "execution reverted : invalid id"
    }
  ]
}

### succeed
{
  requestId: "4ee3ed57-b785-4196-9018-7b682c7a8048",
  expiredAt: 1667893310,
  action: "executeContract",
  transactions: [
    { 
      status: "succeed",
      txHash: "0x5a4e16cfe0c21c3cd20456340b8614f585d951d9b931b515b11575d08142a6e2",
      errorMessage: null
    }
  ]
}
*/

Last updated