Get fees for a specific transaction

How to get the gas fee for a specific transaction such as an NFT Transfer, Token Transfer, Contract Execution, etc.

The cost of a specific transaction on the blockchain is dependent on the complexity of that transaction. The complexity of a transaction is expressed in the amount of "gas" that is required to execute this transaction. A more complex transaction requires a higher gas amount.

This means that the fee that needs to be paid for a specific transaction is the following:

fee-for-a-transaction = amount-of-gas-needed * gas-price-at-that-moment

This endpoint adds all the necessary details to a generic transaction request, like the necessary GAS fees, etc.

To retrieve the gas needed to execute a certain blockchain transaction, the build transaction endpoint can be used.

Request Endpoint: reference

POST https://api-wallet.venly.io/api/transactions/build

Example Request:

POST https://api-wallet.venly.io/api/transactions/build
{
    "type": "TRANSFER",
    "secretType": "MATIC",
    "walletId": "2b358962-4467-4f41-ab93-2b6395d8ae16",
    "to": "0x2Eaf85AF290759770CF98BF83aa640DC2A63daDf",
    "value": 10
}

Response Body:

{
    "success": true,
    "result": {
        "walletId": "2b358962-4467-4f41-ab93-2b6395d8ae16",
        "gasPrice": 20000000000,
        "gas": 21000,
        "value": 10000000000000000000,
        "to": "0x2Eaf85AF290759770CF98BF83aa640DC2A63daDf",
        "type": "MATIC_TRANSACTION"
    }
}

๐Ÿ“˜

  • gas represents the maximum amount of gas you allow to be spent on this transaction
  • gasPrice is the price for one unit of gas

Transaction Request Examples

The following transaction types can be used when building a transaction:

TRANSFER

{
    "type": "TRANSFER",
    "secretType": "MATIC",
    "walletId": "2b358962-4467-4f41-ab93-2b6395d8ae16",
    "to": "0x2Eaf85AF290759770CF98BF83aa640DC2A63daDf",
    "value": 10
}

GAS_TRANSFER

 {
    "type": "GAS_TRANSFER",
    "secretType": "MATIC",
    "walletId": "2b358962-4467-4f41-ab93-2b6395d8ae16",
    "to": "0x2Eaf85AF290759770CF98BF83aa640DC2A63daDf",
    "value": 10
}

TOKEN_TRANSFER

{
    "type": "TOKEN_TRANSFER",
    "secretType": "ETHEREUM",
    "tokenAddress": "0x07865c6e87b9f70255377e024ace6630c1eaa37f",
    "walletId": "2b358962-4467-4f41-ab93-2b6395d8ae16",
    "to": "0x2Eaf85AF290759770CF98BF83aa640DC2A63daDf",
    "value": 1
}

NFT_TRANSFER

{
    "type": "NFT_TRANSFER",
    "secretType": "ETHEREUM",
    "tokenAddress": "0x77f57f9ac6c52ce5aa9d19a57d0aee82be7e73f9",
    "walletId": "2b358962-4467-4f41-ab93-2b6395d8ae16",
    "to": "0x2Eaf85AF290759770CF98BF83aa640DC2A63daDf",
    "tokenId": 1
}

CONTRACT_EXECUTION

{
    "type": "CONTRACT_EXECUTION",
	"walletId": "2b358962-4467-4f41-ab93-2b6395d8ae16",
	"to": "0xdc71b72db51e227e65a45004ab2798d31e8934c9",
	"secretType": "ETHEREUM",
	"functionName": "transfer",
	"value": 1,
	"inputs": [{
		"type": "address",	
    	"value": "0x80cbb6c4342948e5be81987dce8251dbedd69138"
	}, {
		"type": "uint256",
		"value": 73680000
	}]
}