Who is this tutorial for:
- API users that want to calculate the transaction fee of a transaction before sending
Brief Outline
-
sendDeviceForSigning: booleanis 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: falsethe transaction values (including the transaction fee) will be calculated but will NOT be saved in TrustVault platform (you can think ofsendDeviceForSigning: falseas 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: falseto allow TrustVault to calculate the fees for you -
Send the transaction using the values from 1 using either the graphQL query with
sendDeviceForSigning: trueor the SDK
Calculating Ethereum Transaction Fee
mutation ethereumTransactionFee(
$from: String!
$to: String!
$value: String!
$assetSymbol: String!
$speed: TransactionSpeed
$currency: String
$sendToDevicesForSigning: Boolean
) {
createEthereumTransaction(
createTransactionInput: {
ethereumTransaction: {
to: $to
assetSymbol: $assetSymbol
value: $value
fromAddress: $from
speed: $speed
}
currency: $currency
source: "API"
sendToNetworkWhenSigned: true
sendToDevicesForSigning: $sendToDevicesForSigning
}
) {
assetRate
chainRate
signData {
transaction {
to
fromAddress
value
gasPrice
gasLimit
}
}
}
}Variables:
{
"from": "<FROM_BITPANDA_CUSTODY_ADDRESS>",
"to":"0xaa8f71f62c93f705d70e47748987548b31c0d67e",
"value": "<TRANSACTION_VALUE_IN_WEI>",
"assetSymbol": "ETH",
"speed": "SLOW" | "MEDIUM" | "FAST",
"currency": "GBP",
"sendToDevicesForSigning": false
}Response:
{
"data": {
"createEthereumTransaction": {
"chainRate": "3487.9665",
"assetRate": "3487.9665",
"signData": {
"transaction": {
"to": "0xaa8f71f62c93f705d70e47748987548b31c0d67e",
"fromAddress": "0x2F46147dE40e96Ae55a6cC68560645e69eB703e6",
"value": "1",
"gasPrice": "130000000000",
"gasLimit": "21000",
}
}
}
}
}- gasPrice - price per unit of gas in satoshi
- 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:
-
$speedis now replaced by$gasPriceand$gasLimitvalues
mutation createEthereumTransaction (
$from: String!
$to: String!
$value: String!
$assetSymbol: String!
$currency: String
$gasPrice: String
$gasLimit: String
$sendToDevicesForSigning: Boolean
) {
createEthereumTransaction(
createTransactionInput: {
ethereumTransaction: {
to: $to
assetSymbol: $assetSymbol
value: $value
fromAddress: $from
gasPrice: $gasPrice
gasLimit: $gasLimit
}
currency: $currency
source: "API"
sendToNetworkWhenSigned: true
sendToDevicesForSigning: $sendToDevicesForSigning
}
) {
assetRate
chainRate
signData {
transaction {
to
fromAddress
value
gasPrice
gasLimit
nonce
chainId
data
}
}
}
}Variables:
NOTE:
-
set
"sendToDevicesForSigning": trueto create the transaction -
speedis now replaced bygasPriceandgasLimit
{
"from": "<FROM_BITPANDA_CUSTODY_ADDRESS>",
"to":"0xaa8f71f62c93f705d70e47748987548b31c0d67e",
"value": "<TRANSACTION_VALUE_IN_WEI>",
"assetSymbol": "ETH",
"gasPrice": "<GAS_PRICE_RESULT_FROM_PREVIOUS_CALL>",
"gasLimit": "<GAS_LIMIT_RESULT_FROM_PREVIOUS_CALL>",
"currency": "GBP",
"sendToDevicesForSigning": true
}SDK:
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
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)see more: TrustVault Node.js SDK