Options
All
  • Public
  • Public/Protected
  • All
Menu

HancockEthereumSmartContractService

Introduction

We can use this interface to manage operations related with Ethereum smart contracts over blockchain

Smart contract deployment

  const hancockEthClient = new HancockEthereumClient(config);

  const result = await hancockEthClient.smartContract.deploy(
    '0x34C54CB0d5cD1c0f5240324618adAD15ad6646AF',
    {privateKey: '0xd06026d5b8664036bdec0a924b8c7360566e678a2291e9440156365b040a7b83'},
    'https://s3-eu-west-1.amazonaws.com/ethereum/eip20/EIP20',
    'EIP20',
    ['1000', 'HancockTest1', '18', 'HT1']
  );
  console.log(result);

Console output:

{
  blockHash: '0x4c5dae42c9ea1b90912b6f7128a9d1213d14f70ca12b06f417b4d519b8cfe543';
  blockNumber: 4460598;
  transactionId: '0x241dbc176195e58c7505812e7c9a04bd83c5dd59b0684e39911f88bedce5c6bf';
  from: '0x8a37b79e54d69e833d79cac3647c877ef72830e1';
  to: null;
  value: IHancockSocketCurrency;
  data: '';
  fee: IHancockSocketCurrency;
  newContractAddress: '0x54a298ee9fccbf0ad8e55bc641d3086b81a48c41';
  timestamp: 1559038793;
}

Smart contract invoke

  const hancockEthClient = new HancockEthereumClient(config);

  const result = await hancockEthClient.smartContract.invoke(
    'token-contract-alias',
    'balanceOf',
    ['0x34C54CB0d5cD1c0f5240324618adAD15ad6646AF'],
    '0x34C54CB0d5cD1c0f5240324618adAD15ad6646AF',
    {privateKey: '0xd06026d5b8664036bdec0a924b8c7360566e678a2291e9440156365b040a7b83'}
  );
  console.log(result);

Console output:

{
  success: true,
  transactionHash: '0x241dbc176195e58c7505812e7c9a04bd83c5dd59b0684e39911f88bedce5c6bf'
}

Subscribe to smart contract deployment

  const hancockEthClient = new HancockEthereumClient(config);

  const subscription = hancockEthClient.smartContract.subscribeToDeployments([
    '0x34C54CB0d5cD1c0f5240324618adAD15ad6646AF',
  ]);
  subscription.on(CONSUMER_EVENT_KINDS.SmartContractDeployment, (data) => { console.log(data) });
  subscription.on(CONSUMER_EVENT_KINDS.Error, (error) => { console.error(error) });

Subscribe to smart contract transactions

  const hancockEthClient = new HancockEthereumClient(config);

  const subscription = hancockEthClient.smartContract.subscribeToTransactions([
    'contract-alias',
  ]);
  subscription.on(CONSUMER_EVENT_KINDS.SmartContractTransaction, (data) => { console.log(data) });
  subscription.on(CONSUMER_EVENT_KINDS.Error, (error) => { console.error(error) });

Subscribe to smart contract events

  const hancockEthClient = new HancockEthereumClient(config);

  const subscription = hancockEthClient.smartContract.subscribeToEvents([
    'contract-alias',
  ]);
  subscription.on(CONSUMER_EVENT_KINDS.SmartContractEvent, (data) => { console.log(data) });
  subscription.on(CONSUMER_EVENT_KINDS.Error, (error) => { console.error(error) });

Hierarchy

  • HancockEthereumSmartContractService

Index

Constructors

constructor

Methods

call

  • call(contractAddressOrAlias: string, method: string, params: string[], from: string): Promise<HancockCallResponse>
  • Makes a call to an smart contract method. Calls only fetch information from blockchain so it doesn't consume gas

    Parameters

    • contractAddressOrAlias: string

      Address or alias of the smart contract registered in Hancock

    • method: string

      The name of the method to call

    • params: string[]

      An array of arguments passed to the method

    • from: string

      The address of the account doing the call

    Returns Promise<HancockCallResponse>

    The returned value from the smart contract method

callAbi

  • callAbi(contractAddressOrAlias: string, method: string, params: string[], from: string, abi: any): Promise<HancockCallResponse>
  • Makes an invocation to an smart contract method with abi. Invocations are used to call smart contract methods that writes information in the blockchain consuming gas

    Parameters

    • contractAddressOrAlias: string

      Address or alias of the smart contract registered in Hancock

    • method: string

      The name of the method to call

    • params: string[]

      An array of arguments passed to the method

    • from: string

      The address of the account doing the call

    • abi: any

      raw in json format

    Returns Promise<HancockCallResponse>

    The returned value from the smart contract method

deploy

  • Makes an invocation to an smart contract method. Invocations are used to call smart contract methods that writes information in the blockchain consuming gas

    Parameters

    • from: EthereumAddress

      The address of the account doing the call

    • Default value options: HancockInvokeOptions = {}

      Configuration of how the transaction will be send to the network

    • urlBase: string

      Public URL where the .bin and .abi are

    • constructorName: string

      The name of the constructor to call

    • Default value constructorParams: string[] = []

      An array of arguments passed to the method

    Returns Promise<HancockTransactionEventBody>

    The returned value from the smart contract method

getAllContracts

  • getAllContracts(): Promise<HancockContractInstance[]>
  • Get the list of all contracts registered in Hancock

    Returns Promise<HancockContractInstance[]>

    The list of all contracts registered in Hancock

invoke

  • Makes an invocation to an smart contract method. Invocations are used to call smart contract methods that writes information in the blockchain consuming gas

    Parameters

    • contractAddressOrAlias: string

      Address or alias of the smart contract registered in Hancock

    • method: string

      The name of the method to call

    • params: string[]

      An array of arguments passed to the method

    • from: string

      The address of the account doing the call

    • Default value options: HancockInvokeOptions = {}

      Configuration of how the transaction will be send to the network

    Returns Promise<HancockSignResponse>

    The returned value from the smart contract method

invokeAbi

  • Makes an invocation to an smart contract method with abi. Invocations are used to call smart contract methods that writes information in the blockchain consuming gas

    Parameters

    • contractAddressOrAlias: string

      Address or alias of the smart contract registered in Hancock

    • method: string

      The name of the method to call

    • params: string[]

      An array of arguments passed to the method

    • from: string

      The address of the account doing the call

    • Default value options: HancockInvokeOptions = {}

      Configuration of how the transaction will be send to the network

    • abi: any

      raw in json format

    Returns Promise<HancockSignResponse>

    The returned value from the smart contract method

register

  • Register a new smart contract instance in Hancock

    Parameters

    • alias: string

      An alias for the smart contract

    • address: DltAddress

      The address of the deployed smart contract instance

    • abi: EthereumAbi

      The application binary interface (abi) of the deployed smart contract

    Returns Promise<HancockRegisterResponse>

    The result of the request

subscribeToDeployments

  • Create a websocket subscription to watch transactions of type "smart contract transactions" in the network

    Parameters

    • Default value addresses: string[] = []

      An array of address that will be added to the watch list

    • Default value consumer: string = ""

      A consumer plugin previously configured in hancock that will handle each received event

    Returns HancockEthereumSocket

    An event emitter that will fire the watched "smart contract transactions" events

subscribeToEvents

  • Create a websocket subscription to watch transactions of type "smart contract events" in the network

    Parameters

    • Default value contracts: string[] = []

      An array of address of smart contracts that will be added to the watch list

    • Default value consumer: string = ""

      A consumer plugin previously configured in hancock that will handle each received event

    Returns HancockEthereumSocket

    An event emitter that will fire the watched "smart contract events" events

subscribeToTransactions

  • Create a websocket subscription to watch transactions of type "smart contract transactions" in the network

    Parameters

    • Default value contracts: string[] = []

      An array of address of smart contracts that will be added to the watch list

    • Default value consumer: string = ""

      A consumer plugin previously configured in hancock that will handle each received event

    Returns HancockEthereumSocket

    An event emitter that will fire the watched "smart contract transactions" events

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