js-conflux-sdk
Version:
JavaScript Conflux Software Development Kit
86 lines • 2.92 kB
TypeScript
export = FunctionCoder;
declare class FunctionCoder {
/**
* Function coder
*
* @param {object} options
* @param {string} [options.name]
* @param {array} [options.inputs]
* @param {array} [options.outputs]
* @param {string} [options.stateMutability='nonpayable']
*
* @example
* > abi = { name: 'func', inputs: [{ type: 'int' }, { type: 'bool' }], outputs: [{ type: 'int' }] }
* > coder = new FunctionCoder(abi)
FunctionCoder {
name: 'func',
fullName: 'func(int256 , bool )',
inputs: [ { type: 'int' }, { type: 'bool' } ],
outputs: [ { type: 'int' } ],
type: 'func(int256,bool)'
}
*/
constructor({ name, inputs, outputs, stateMutability }: {
name?: string;
inputs?: any[];
outputs?: any[];
stateMutability?: string;
});
name: string;
fullName: string;
type: string;
signature: any;
stateMutability: string;
inputCoder: import("../abi/BaseCoder");
outputCoder: import("../abi/BaseCoder");
/**
* Get function signature by abi (json interface)
*
* @param {array} args
* @return {string}
*
* @example
* > abi = { name: 'func', inputs: [{ type: 'int' }, { type: 'bool' }], outputs: [{ type: 'int' }] }
* > coder = new FunctionCoder(abi)
* > coder.encodeData([100, true])
"0x1eee72c100000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000001"
*/
encodeData(args: any[]): string;
/**
* Decode data hex with inputs by abi (json interface)
*
* @param {string} hex - Hex string
* @return {array} NamedTuple
*
* @example
* > abi = { name: 'func', inputs: [{ type: 'int' }, { type: 'bool' }], outputs: [{ type: 'int' }] }
* > coder = new FunctionCoder(abi)
* > result = coder.decodeData('0x15fb272000000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000001')
NamedTuple(0,1) [ 100n, true ]
* > console.log([...result])
[ 100n, true ]
* > console.log(result[0])
100
* > console.log(result[1])
true
*/
decodeData(hex: string): any[];
/**
* Decode hex with outputs by abi (json interface)
*
* @param {string} hex - Hex string
* @return {array} NamedTuple
*
* @example
* > abi = { name: 'func', inputs: [{ type: 'int' }, { type: 'bool' }], outputs: [{ type: 'int' }] }
* > coder = new FunctionCoder(abi)
* > result = coder.decodeOutputs('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff')
NamedTuple(0) [ -1n ]
* > console.log([...result])
[-1n]
* > console.log(result[0])
-1n
*/
decodeOutputs(hex: string): any[];
}
//# sourceMappingURL=FunctionCoder.d.ts.map