invoke

Invoke allows for the generic execution of smart contracts on behalf of the user. It is reccommended to have a general understanding of the NEO blockchain, and to be able successfully use all other commands listed previously in this document before attempting a generic contract execution.

Input Arguments

ParameterDescription

scriptHash: string

Script hash of the smart contract to invoke

operation: string

Operation on the smart contract to call

Any input arguments for the operation

fee?: string

The parsed amount of network fee (in GAS) to include with transaction

network?: string

Network to submit this request to. If omitted, will default to network the wallet is currently set to

Describes the assets to attach with the smart contract, e.g. attaching assets to mint tokens during a token sale

A hard override of all transaction utxo inputs and outputs.

IMPORTANT: If provided, fee and attachedAssets will be ignored.

triggerContractVerification?: boolean

Adds the instruction to invoke the contract verification trigger

broadcastOverride?: boolean

In the case that the dApp would like to be responsible for broadcasting the signed transaction rather than the wallet provider

Adds transaction attributes for the "Hash" usage block

Argument

ParameterDescription

type: 'String' | 'Boolean' | 'Hash160' | 'Hash256' | 'Integer' | 'ByteArray' | 'Array' | 'Address'

The type of the argument with you are using

value: any

String representation of the argument which you are using

TxHashAttribute

ParameterDescription

type: 'String' | 'Boolean' | 'Hash160' | 'Hash256' | 'Integer' | 'ByteArray' | 'Array' | 'Address'

The type of the argument with you are using

value: any

String representation of the argument which you are using

txAttrUsage: 'Hash1' | 'Hash2' | 'Hash3' | 'Hash4' | 'Hash5' | 'Hash6' | 'Hash7' | 'Hash8' | 'Hash9' | 'Hash10' | 'Hash11' | 'Hash12' | 'Hash13' | 'Hash14' | 'Hash15'

Attribute usage value

AttachedAssets

ParameterDescription

NEO?: string

The amount of NEO to attach to the contract invocation

GAS?: string

The amount of GAS to attach to the contract invocation

AssetIntentOverrides

ParameterDescription

A list of UTXO inputs to use for this transaction

A list of UTXO outputs to use for this transaction

AssetInput

ParameterDescription

txid: string

Transaction id to be used as input

index: number

Index of the UTXO, can be found from transaction details

AssetOutput

ParameterDescription

asset: string

Asset of the UTXO

address: string

Address to receive the UTXO

value: string

String representation of double or integer value to be used as output

Success Response

In the case where the "broadcastOverride" input argument is not set, or set to false.

ParameterDescription

txid: string

The transaction ID of the invocation

nodeURL: string

The node which the transaction was broadcast to. Returned if transaction is broadcast by wallet provider

In the case where the "broadcastOverride" input argument is set to True.

ParameterDescription

txid: string

The transaction ID of the invocation

signedTx: string

The serialized signed transaction. Only returned if the broadcastOverride input argument was set to True

Error Response

ParameterDescription

type: string

The type of error which has occured

description: string

A description of the error which has occured

data: string

Any raw data associated with the error

Example

Request

neoline.invoke({
  scriptHash: 'af7c7328eee5a275a3bcaee2bf0cf662b5e739be',
  operation: 'balanceOf',
  args: [
    {
      type: 'Hash160',
      value: '91b83e96f2a7c4fdf0c1688441ec61986c7cae26'
    }
  ],
  attachedAssets: {
    NEO: '1',
    GAS: '0.0001'
  },
  fee: '0.001',
  network: 'TestNet',
  broadcastOverride: false,
  txHashAttributes: [
    {
      type: 'Boolean',
      value: true,
      txAttrUsage: 'Hash1'
    }
  ]
})
.then(result => {
  console.log('Invoke transaction success!');
  console.log('Transaction ID: ' + result.txid);
  console.log('RPC node URL: ' + result.nodeURL);
})
.catch((error) => {
  const {type, description, data} = error;
  switch(type) {
    case 'NO_PROVIDER':
        console.log('No provider available.');
        break;
    case 'RPC_ERROR':
        console.log('There was an error when broadcasting this transaction to the network.');
        break;
    case 'CANCELED':
        console.log('The user has canceled this transaction.');
        break;
    default:
        // Not an expected error object.  Just write the error to the console.
        console.error(error);
        break;
  }
});

Response

{
  txid: 'd08c5f58675376832480f2959732caa2a0e024ad0304ed77c62146a9621124d6',
  nodeUrl: 'https://testnet.api.neoline.io'
};

最后更新于