You are viewing a single comment's thread from:

RE: Are you overpaying for Ether transactions?

in #bitcoin6 years ago

Yes of course. I monitor her closely. I try my best to respond quickly every time anyone responds to her. I would have the same question though. BTW I use this site, it seems to do a better job...
https://etherscan.io/gastracker

If you have the luxury of doing this with code, you can use this little snippet...

async function defaultParams(fromAddr){
    let params = {
        from : fromAddr,
        gas : 300000
    };

    let gasPrice = await web3.eth.getGasPrice();
    params.gasPrice = gasPrice;

    console.log("params: ",params);
    return params;
}

async function sendFundsToOwners(){

    let balance = await web3.eth.getBalance(agentAddress);
    
    console.log("Agent Balance is: ",balance);
    let toSend = Math.ceil(balance * 0.9999);
    console.log("Sending "+toSend+" WEI");

    let txData = {
        to: partnersAddress,
        value: toSend
    }

    let gasPrice = await web3.eth.getGasPrice();
    console.log("gasPrice: ",gasPrice);
    txData.gasPrice = gasPrice;
    txData.gas = await web3.eth.estimateGas(txData);
    txData.value = toSend - (txData.gasPrice * txData.gas);
    console.log("txData: ",txData);
    let signedTx = await account.signTransaction(txData);
    console.log("signedTx: ",signedTx);
    try{
        let result = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);
        console.log("Result of send: ",result);
        return result;
    }catch(error){
        console.error(error);
        sendFundsToOwners();
    }
}

There are two different functions here doing 2 different things.
The first is a shorthand way of getting the current gas price, it uses a web3js function that takes the average of the last 50 blocks or so. Works for metamask or mist, but won't work with infura.

The second is a sweep function, designed to work with clientside signing such as would be the case if you're using infura, where there isn't a wallet to speak of.

Assume agent address is the address of your dapp controller. I use that to sweep funds collected in my dapps such as flairdrop, to an agent and then when the agent has more money than it needs for awhile, I have it sweep the remainder to me.

Either way gas price is a crucial thing and the wallets get this SOOO wrong, SOOO often. Nothing like sending a tx with the recommended 1 GWEI only to find out it's currently 100 GWEI to get confirmed before the second coming. Or sending with 100 GWEI only to find the blockchain has calmed down and now you've spent 99x what you needed to.

Sort:  

Yeah, you can definitely modify the gas price manually by changing some of the code on MyEtherWallet. I find that the preset gas price changes sometimes when I visit the website and I accidentally over or underpay as well. Some of what you are saying I understand easily, but I'm only a little educated in coding.

Anyways, thanks for this comment. It's helpful to see it in code form. And to answer your question from earlier. I wish I had bought XRP back in 2016, but I think crypto isn't over yet.

Changing the gas manually can attract the security issue to the transaction?

I think I understand your question. If you change the gas price correctly it shouldn't have any effect on the security, even if you change it manually you should be fine.

The gas price doesn't affect security at all. However it can mean the difference between getting confirmed in a reasonable 1 to 2 minutes or waiting hours or even days for it to confirm. Always, always, always check the current gas price before sending because your wallet is going to get this wrong 9 out of 10 times when there is heavy cycling in the prices.

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 59880.83
ETH 2301.55
USDT 1.00
SBD 2.50