Options
All
  • Public
  • Public/Protected
  • All
Menu

HancockEthereumTokenService

Introduction

We can use this interface to manage operations related with ERC20 Ethereum tokens over blockchain

Token registration

  const hancockEthClient = new HancockEthereumClient(config);

  const result = await hancockEthClient.token.register(
    'token-contract-alias',
    '0x28a0686efb7dd9b625288a08649a6278cc4fd154'
  );
  console.log(result);

Console output:

{
  success: true
}

Transfer token

  const hancockEthClient = new HancockEthereumClient(config);

  const result = await hancockEthClient.token.transfer(
    '0x34C54CB0d5cD1c0f5240324618adAD15ad6646AF',
    '0x28a0686efb7dd9b625288a08649a6278cc4fd154',
    250000000,
    'token-contract-alias',
    {
      privateKey: '0xd06026d5b8664036bdec0a924b8c7360566e678a2291e9440156365b040a7b83'
    }
  );
  console.log(result);

Console output:

{
  success: true
}

Transfer token from

  const hancockEthClient = new HancockEthereumClient(config);

  const result = await hancockEthClient.token.transferFrom(
    '0x34C54CB0d5cD1c0f5240324618adAD15ad6646AF',
    '0x28a0686efb7dd9b625288a08649a6278cc4fd154',
    '0x6c0a14f7561898b9ddc0c57652a53b2c6665443e',
    250000000,
    'token-contract-alias',
    {
      privateKey: '0xd06026d5b8664036bdec0a924b8c7360566e678a2291e9440156365b040a7b83'
    }
  );
  console.log(result);

Console output:

{
  success: true
}

Allowance to transfer tokens

  const hancockEthClient = new HancockEthereumClient(config);

  const result = await hancockEthClient.token.allowance(
    '0x34C54CB0d5cD1c0f5240324618adAD15ad6646AF',
    '0x6c0a14f7561898b9ddc0c57652a53b2c6665443e',
    '0x6c0a14f7561898b9ddc0c57652a53b2c6665443e',
  );
  console.log('allowance: ' + result);

Console output:

allowance: 12

Get token balance

  const hancockEthClient = new HancockEthereumClient(config);

  const result = await hancockEthClient.token.getBalance(
    'contract-alias',
    '0x6c0a14f7561898b9ddc0c57652a53b2c6665443e'
  );
  console.log(result);

Console output:

{
  balance: "120000000000000000",
  decimals: 18
}

Get token balance

  const hancockEthClient = new HancockEthereumClient(config);

  const result = await hancockEthClient.token.getBalance(
    'contract-alias',
    '0x6c0a14f7561898b9ddc0c57652a53b2c6665443e'
  );
  console.log(result);

Console output:

{
  balance: "120000000000000000",
  decimals: 18
}

Approve transfer

  const hancockEthClient = new HancockEthereumClient(config);

  const result = await hancockEthClient.token.approve(
    '0x6c0a14f7561898b9ddc0c57652a53b2c6665443e',
    '0x34C54CB0d5cD1c0f5240324618adAD15ad6646AF',
    '3',
    'contract-alias',
    {
      privateKey: '0xd06026d5b8664036bdec0a924b8c7360566e678a2291e9440156365b040a7b83'
    }
  );
  console.log(result);

Console output:

{
  success: true
}

Hierarchy

  • HancockEthereumTokenService

Index

Constructors

constructor

Methods

allowance

  • Returns the amount of tokens approved by the owner that can be transferred to the spender's account

    Parameters

    • from: string

      The caller's address

    • tokenOwner: string

      The token owner's address

    • spender: string

      The token spender's address

    • addressOrAlias: string

      Address or alias of the token smart contract registered in Hancock

    Returns Promise<HancockTokenAllowanceResponse>

    The result of the request

approve

  • Token owner can approve for spender to transferFrom(...) tokens from the token owner's account

    Parameters

    • from: string

      The token owner's address

    • spender: string

      The token spender's address

    • value: string

      The amount of tokens to transfer (in weis)

    • addressOrAlias: string

      Address or alias of the token smart contract registered in Hancock

    • Default value options: HancockInvokeOptions = {}

      Configuration of how the transaction will be send to the network

    Returns Promise<HancockSignResponse>

    The result of the request

getAllTokens

  • getAllTokens(): Promise<HancockTokenInstance[]>
  • Get the list of all tokens registered in Hancock

    Returns Promise<HancockTokenInstance[]>

    The list of all tokens registered in Hancock

getBalance

  • Get the token balance for account tokenOwner

    Parameters

    • addressOrAlias: string

      Address or alias of the token smart contract registered in Hancock

    • tokenOwner: string

      The token owner's address

    Returns Promise<HancockTokenBalanceResponse>

    The result of the request with the balance

getMetadata

  • Retrieves the metadata of the token

    Parameters

    • addressOrAlias: string

      Address or alias of the token smart contract registered in Hancock

    Returns Promise<HancockTokenMetadataResponse>

    name, symbol, decimals, and totalSupply of the token

register

  • Register a new ERC20 token instance in Hancock

    Parameters

    • alias: string

      An alias for the token

    • address: DltAddress

      The address of the deployed smart contract token instance

    Returns Promise<HancockTokenRegisterResponse>

    The result of the request

transfer

  • Transfer the balance from token owner's account to to account

    • Owner's account must have sufficient balance to transfer
    • 0 value transfers are allowed

    Parameters

    • from: string

      The token sender's address

    • to: string

      The token receiver's address

    • value: string

      The amount of tokens to transfer (in weis)

    • addressOrAlias: string

      Address or alias of the token smart contract registered in Hancock

    • Default value options: HancockInvokeOptions = {}

      Configuration of how the transaction will be send to the network

    Returns Promise<HancockSignResponse>

    The result of the request

transferFrom

  • Transfer tokens from the sender account to the to account The calling account must already have sufficient tokens approved for spending from the sender account and

    • Sender account must have sufficient balance to transfer
    • Spender must have sufficient allowance to transfer
    • 0 value transfers are allowed

    Parameters

    • from: string

      The aproved spender's address

    • sender: string

      The token sender's address

    • to: string

      The token receiver's address

    • value: string

      The amount of tokens to transfer (in weis)

    • addressOrAlias: string

      Address or alias of the token smart contract registered in Hancock

    • Default value options: HancockInvokeOptions = {}

      Configuration of how the transaction will be send to the network

    Returns Promise<HancockSignResponse>

    The result of the request

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc