Skip to content

API: web3 avm abi

John edited this page Jun 5, 2019 · 2 revisions

The web3.avm.abi functions let you decode and encode parameters to ABI (Application Binary Interface) for function calls to the Aion Virtual Machine (AVM).

encode

web3.avm.abi.encode(types, values);

Encodes a set of parameters' data types and their values to create an ABI signature.

Parameters

  1. types - Array<String>: An array of strings which identify the data types used parameters. This array needs to be the same length as the values array as for every data type, there must be a matching value.
  2. values - Array<Mixed>: An array of strings, numbers, or arrays which contains the values to be used as parameters. This array needs to be the same length as the types array as for every argument value, there must be a matching data type.

Returns

String - The ABI signature of the parameters' data types and values

Example

web3.avm.abi.encode([ "string" ], [ "Hello World" ])
> 0x21000b48656c6c6f20576f726c64

encodeMethod

web3.avm.abi.encodeMethod(method, types, values);

Encodes the method's signature to its ABI signature with its name, arguments data types, and arguments values; based on abstraction from the aforementioned web3.avm.encode method.

Parameters

  1. method - String: The method name to encode
  2. types - Array<String>: An array of strings which identify the data types used by the method in its arguments. This array needs to be the same length as the values array as for every data type, there must be a matching value.
  3. values - Array<Mixed>: An array of strings, numbers, or arrays which contains the values to be used by the method as arguments. This array needs to be the same length as the types array as for every argument value, there must be a matching data type.

Returns

String - The ABI signature of the method.

Example

web3.avm.abi.encodeMethod("setString", [ "string" ], [ "Hello World" ]) 
> 0x210009736574537472696e6721000b48656c6c6f20576f726c64

decode

web3.avm.abi.decode(type, data);

Encodes a hex string based on the data type used for the hex string.

Parameters

  1. type - String: A string which identifies the data-type to use decode data into
  2. data - Hexstring: A hex string which is usually the ABI Signature of something encoded from the AVM

Returns

Mixed - The decoded result of the encoded data.

Example

web3.avm.abi.decode("string", 0x21000b48656c6c6f20576f726c64)
> "Hello World"

getCoder

web3.avm.abi.getCoder(type);

Returns a data type coder which handles the encoding and decoding for data types and their values for the AVM.

Parameters

  1. type - String: Used to define the type of data type coder to return

Returns

Object - An object Coder which is used to handle the encoding and decoding of data types and their values for the AVM

Example

web3.avm.abi.getCoder('string')
> StringCoder { type: 'String', tag: 33, localName: null }

getReader

web3.avm.abi.getReader(data);

Returns a reader used to handle the decoding of data which was originally encoded for the AVM.

Parameters

  1. data - Uint8Array: The data to be read and decoded

Returns

Object - An object Reader which is used for the decoding of data which was originally encoded for the AVM

Example

web3.avm.abi.getReader(0x21000b48656c6c6f20576f726c64)
> Reader {
  _data: Uint8Array [ 33, 0, 11, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100 ],
  _offset: 0
}

getWriter

web3.avm.abi.getWriter();

Returns a writer used to handle the encoding of data for the AVM.

Returns

Object - An object Writer which is used for the encoding of data for the AVM

Example

web3.avm.abi.getWriter()
> Writer { _data: Uint8Array [] }

readyDeploy

web3.avm.abi.readyDeploy(jarPath, encodedArgs);

Performs big-endian encoding on a compiled AVM Contract's jar and the encoded arguments for that contract's initializer. This combined result is then used to deploy through normal means of sending a transaction.

Parameters

  1. jarPath - Jar File: A jar file of a compiled AVM Contract
  2. encodedArgs - Hexstring: A hex string which is usually the ABI Signature of something encoded from the AVM

Returns

Mixed - The combined encoded data for the deployment of an AVM Contract.

Example

web3.avm.abi.readyDeploy(path.join(__dirname, 'contracts', 'HelloAVM-1.0-SNAPSHOT.jar'), 0x210009736574537472696e6721000b48656c6c6f20576f726c64)

Clone this wiki locally