stellar-api icon indicating copy to clipboard operation
stellar-api copied to clipboard

How do increase transaction fee?

Open zottirik opened this issue 5 years ago • 1 comments

How do increase transaction fee?

zottirik avatar Mar 13 '19 13:03 zottirik

It's currently hardcoded in. I have some significant modifications to the repo internally that I'll eventually push. In the meantime, what you're looking for is adding this method to src/Transaction/TransactionBuilder.php:

    /**
     * Allow for adjustable fee.
     *
     * @param $fee
     */
    public function setFee($fee)
    {
        if (!is_int($fee) || ($fee < 100)) {
            $this->baseFee = 100;
        } else {
            $this->baseFee = $fee;
        }

        return $this;
    }

Here's example usage for you where fee is in stroops with a default of 100:

$server = Server::testNet();
$transaction = $server
                ->buildTransaction($sourceAccountPublicKey)
                ->setFee(5000)
                ->addOperation(
                    new CreateAccountOp($newAccountPublicKey, 151, $sourceAccountPublicKey)
                );

Note that adjusting this fee is on a per operation basis. The total fee of a transaction is calculated as baseFee * operationsCount.

cballou avatar Dec 06 '19 01:12 cballou