Exactly!
I traced it back in the stack
encodeParameters() function is called from the below method, which then calls the above mentioned formatParam()
" return abi.encodeParameters(inputs, args).replace(‘0x’, ‘’); "
But in the below method, I think the args is initialized as empty and I don’t know the reason for that
" args = this.arguments || []; "
Btw I did not write index.js
Its a part of Web3.js
Contract.prototype._encodeMethodABI = function _encodeMethodABI() {
var methodSignature = this._method.signature, args = this.arguments || [];
var signature = false, paramsABI = this._parent.options.jsonInterface.filter(function (json) {
return ((methodSignature === 'constructor' && json.type === methodSignature) ||
((json.signature === methodSignature || json.signature === methodSignature.replace('0x', '') || json.name === methodSignature) && json.type === 'function'));
}).map(function (json) {
var inputLength = (Array.isArray(json.inputs)) ? json.inputs.length : 0;
if (inputLength !== args.length) {
throw new Error('The number of arguments is not matching the methods required number. You need to pass ' + inputLength + ' arguments.');
}
if (json.type === 'function') {
signature = json.signature;
}
return Array.isArray(json.inputs) ? json.inputs : [];
}).map(function (inputs) {
return abi.encodeParameters(inputs, args).replace('0x', '');
})[0] || '';
// return constructor
if (methodSignature === 'constructor') {
if (!this._deployData)
throw new Error('The contract has no contract data option set. This is necessary to append the constructor parameters.');
if (!this._deployData.startsWith('0x')) {
this._deployData = '0x' + this._deployData;
}
return this._deployData + paramsABI;
}
// return method
var returnValue = (signature) ? signature + paramsABI : paramsABI;
if (!returnValue) {
throw new Error('Couldn\'t find a matching contract method named "' + this._method.name + '".');
}
return returnValue;
};