Skip to content
Advertisement

Not including ‘gas’ or ‘gasPrice’ attributes in the ‘options’ object inside of a send() call

Does anyone know what the send() function call to a smart contract method defaults to when you don’t specify gas or gasPrice? Does it automatically allocate sufficient gas and calculate the current average gasPrice? And are those attributes always optional or are there situations where including either one is mandatory?

Advertisement

Answer

From the documentation, both gas and gas seem to always be optional.

Unfortunately the documentation doesn’t state what those will default to when not provided, but having a quick peak at the code (hopefully that’s the right code path) it seems that it calls getGasPrice internally to get the gas price and then default the gasPrice to that.

    // Send the actual transaction
    if (isSendTx && _.isObject(payload.params[0]) && typeof payload.params[0].gasPrice === 'undefined') {

        var getGasPrice = (new Method({
            name: 'getGasPrice',
            call: 'eth_gasPrice',
            params: 0
        })).createFunction(method.requestManager);

        getGasPrice(function (err, gasPrice) {

            if (gasPrice) {
                payload.params[0].gasPrice = gasPrice;
            }

            if (isSendTx) {
                setTimeout(() => {
                    defer.eventEmitter.emit('sending', payload);
                }, 0);
            }

            sendRequest(payload, method);
        });

GitHub Source

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement