๐Ÿš€New Fee Mechanism in Pirichain

With the new version update, a dynamic system transition was made in the fee mechanism.

Weโ€™re excited to announce a recent update that brings more dynamism to blockchain transactions. Previously, transaction fees were static at 0.1 PIRI. With this update, transaction fees are now dynamically calculated based on the blockchainโ€™s congestion and other factors.

By the way minimum fee is increased to 1 PIRI.

Technical Details:

First, import the necessary libraries for cryptographic operations.

const EC = require('elliptic').ec;
const ec = new EC('secp256k1');
const sha = require('sha256');
const req = require('request');

Implement the toHexString function to convert a byte array to a hexadecimal string.

function toHexString(byteArray) {
    return Array.from(byteArray, function (byte) {
        return ('0' + (byte & 0xFF).toString(16)).slice(-2);
    }).join('');
}

Create the getEstimatedFee function to fetch the estimated transaction fee from the blockchain.

async function getEstimatedFee() {
    return new Promise((resolve, reject) => {
        const requestOptionsTransaction = {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
            },
        };
        req.post('https://core.pirichain.com/getEstimatedFee', requestOptionsTransaction, function (f, res) {
            if (!res)
            {
                resolve(1);
                return;
            }
            if (!res.body)
                console.log(res)
            else {
                console.log(res.body);
                const est=JSON.parse(res.body).estimatedBandWidthFee;
                resolve(est);
            }
        });
    })

}

Use the sortObjectProperty function to sort the transaction data before signing.

Implement the prepareSendTokenWithSignature function to organize transaction data.

Use the sendRawTransaction function to sign and send the transaction.

Finally, use the sendRaw function to initiate the transaction process.

With this update, we aim to make blockchain transactions more efficient and responsive to network conditions. We believe that dynamically adjusting transaction fees will lead to a fairer and more sustainable blockchain ecosystem.

Last updated

Was this helpful?