-
Notifications
You must be signed in to change notification settings - Fork 30
API: web3 avm abi
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).
web3.avm.abi.encode(types, values);Encodes a set of parameters' data types and their values to create an ABI signature.
-
types-Array<String>: An array of strings which identify the data types used parameters. This array needs to be the same length as thevaluesarray as for every data type, there must be a matching value. -
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 thetypesarray as for every argument value, there must be a matching data type.
String - The ABI signature of the parameters' data types and values
web3.avm.abi.encode([ "string" ], [ "Hello World" ])
> 0x21000b48656c6c6f20576f726c64web3.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.
-
method-String: The method name to encode -
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 thevaluesarray as for every data type, there must be a matching value. -
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 thetypesarray as for every argument value, there must be a matching data type.
String - The ABI signature of the method.
web3.avm.abi.encodeMethod("setString", [ "string" ], [ "Hello World" ])
> 0x210009736574537472696e6721000b48656c6c6f20576f726c64web3.avm.abi.decode(type, data);Encodes a hex string based on the data type used for the hex string.
-
type-String: A string which identifies the data-type to use decodedatainto -
data-Hexstring: A hex string which is usually the ABI Signature of something encoded from the AVM
Mixed - The decoded result of the encoded data.
web3.avm.abi.decode("string", 0x21000b48656c6c6f20576f726c64)
> "Hello World"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.
-
type-String: Used to define the type of data type coder to return
Object - An object Coder which is used to handle the encoding and decoding of data types and their values for the AVM
web3.avm.abi.getCoder('string')
> StringCoder { type: 'String', tag: 33, localName: null }web3.avm.abi.getReader(data);Returns a reader used to handle the decoding of data which was originally encoded for the AVM.
-
data-Uint8Array: The data to be read and decoded
Object - An object Reader which is used for the decoding of data which was originally encoded for the AVM
web3.avm.abi.getReader(0x21000b48656c6c6f20576f726c64)
> Reader {
_data: Uint8Array [ 33, 0, 11, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100 ],
_offset: 0
}web3.avm.abi.getWriter();Returns a writer used to handle the encoding of data for the AVM.
Object - An object Writer which is used for the encoding of data for the AVM
web3.avm.abi.getWriter()
> Writer { _data: Uint8Array [] }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.
-
jarPath-Jar File: A jar file of a compiled AVM Contract -
encodedArgs-Hexstring: A hex string which is usually the ABI Signature of something encoded from the AVM
Mixed - The combined encoded data for the deployment of an AVM Contract.
web3.avm.abi.readyDeploy(path.join(__dirname, 'contracts', 'HelloAVM-1.0-SNAPSHOT.jar'), 0x210009736574537472696e6721000b48656c6c6f20576f726c64)