1.0.21 • Published 9 months ago

@alpaca-icp/token-adapter v1.0.21

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

Token Adapter

Support ICRC1 ICRC2 EXT DIP20

Note Approve method is not implemented for EXT and DIP20

Usage

import { Token } from "@alpaca-icp/token-adapter";
import { Agent } from "@dfinity/agent";

const agent = new Agent({ host: "https://ic0.app" });

const token = new Token({
  canisterId: "ryjl3-tyaaa-aaaaa-aaaba-cai",
  agent,
  tokenStandard: "ICP",
});

await token.balanceOf("wallet");
await token.getLogo();

// dip 20 token
const Dip20_token = new Token({
  canisterId: "whdfs-saaaa-aaaao-awh4a-cai",
  agent,
  tokenStandard: "DIP20",
});
await Dip20_token.balanceOf("wallet");
await Dip20_token.getLogo();

Token Standard

  • EXT
  • DIP20
  • ICRC1
  • ICRC2 // combination of ICRC1 and ICRC2
  • ICP // icpswap standard for icp

Token interface

export type ApproveInput = {
  fee: [] | [bigint];
  memo: [] | [Uint8Array | number[]];
  from_subaccount: [] | [Uint8Array | number[]];
  created_at_time: [] | [bigint];
  amount: bigint;
  expected_allowance: [] | [bigint];
  expires_at: [] | [bigint];
  spender: {
    owner: Principal;
    subaccount: [] | [Uint8Array | number[]];
  };
};

export type TransferInput = {
  to: {
    owner: Principal;
    subaccount: [] | [Uint8Array | number[]];
  };
  amount: bigint;
  fee: [bigint] | [];
  memo: [Uint8Array | number[]] | [];
  from_subaccount: [] | [Uint8Array | number[]];
  created_at_time: [bigint] | [];
};

export interface IToken {
  actor: TokenActor;
  getDecimals(): Promise<number>;
  balanceOf(
    address:
      | string
      | {
          owner: Principal;
          subaccount: [] | [Uint8Array | number[]];
        }
  ): Promise<number>;
  name(): Promise<string>;
  symbol(): Promise<string>;
  totalSupply(): Promise<number>;
  getFee(): Promise<bigint>;
  getMetadata(): Promise<any>;
  getLogo(): Promise<string>;
  /**
   *
   *  @description This method only work with EXT, ICRC2+ and DIP20 tokens
   */
  approve(input: ApproveInput): Promise<bigint>;

  getFee(): Promise<bigint>;
  transfer(input: TransferInput): Promise<bigint>;
}
1.0.19

9 months ago

1.0.21

9 months ago

1.0.20

9 months ago

1.0.18

9 months ago

1.0.17

9 months ago

1.0.16

9 months ago

1.0.15

9 months ago

1.0.14

9 months ago

1.0.13

9 months ago

1.0.12

9 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago