API users that want to calculate the transaction fee of a transaction before sending
Brief Outline
sendDeviceForSigning: boolean is used to indicate if the transaction request should be saved in TrustVault platform so that the transaction request can be fetched by the iOS app or SDK for signing
If sendDeviceForSigning: false the transaction values (including the transaction fee) will be calculated but will NOT be saved in TrustVault platform (you can think of sendDeviceForSigning: false as a dry run flag). This gives us the chance to see what the transaction values would look like before the transaction request it actually created
Steps
Send a transaction with sendDeviceForSigning: false to allow TrustVault to calculate the fees for you
Send the transaction using the values from 1 using either the graphQL query with sendDeviceForSigning: true or the SDK
gasLimit - total unit of gas the transaction can use
chainRate - the current rate for 1 ETH of the given currency (this can be used to convert the transaction fee from satoshi to the given currency)
assetRate - the current rate for 1 unit of asset to be sent of the given currency (this can be used to convert the asset value to be sent to the given currency)
transaction fee calculation - gasPrice x gasLimit (the transaction fee is in satoshi)
Creating Ethereum Transaction
Ensure that the gasPrice/gasLimit result from the graphQL call above is passed when creating a transaction as gasPrice/gasLimit can change
GraphQL query
NOTE:
$speed is now replaced by $gasPrice and $gasLimit values
Use the gasPrice and gasLimit result from the ethereumTransactionFee graphQL mutation call (see Calculating Ethereum Transaction Fee) when creating an ethereum transaction request as gasPrice/gasLimit can change
1 2 3 4
const gasPrice = result.data?.createEthereumTransaction.signData.transaction.gasPrice; const gasLimit = result.data?.createEthereumTransaction.signData.transaction.gasLimit; const speed = undefined; // speed can be skipped if both gasPrice and gasLimit are manually set const requestId = await trustVault.sendEthereum(fromAddress, toAddress, amount, asset, speed, currency, signCallback, gasPrice, gasLimit)