Send Transactions
To send a cryptocurrency trannsaction user needs a wallet (see Manage User Wallet), sufficient balance on user's blockchain account (see View User Data) and a valid blockchain address of a receipient (see Utilities & Helpers for validation utilities).
Submit Transaction
Use wallet instance obtained by creating, unlocking or recovering user wallet. See Manage User Wallet for details.
Use sendBtcTransaction
and sendEthTransaction
methods to submit Bitcoin and Ethereum transactions.
Bitcoin
Select one account as a sender account and one account as a change account from the list of user accounts, where change between coin being spent and coin receved by receiver will be sent to. Change account can be the same account as the sender account.
Value should be provided in Bitcoin as a string with dot (.) acting as a decimal separator.
Transaction fee rate has to be provided. The faster the fee rate, the faster the transaction will be confirmed. Fee rate can be input manually or one of the suggested fee rates - low, medium or fast - can be used. See Utilities & Helpers for details.
String fromAccountId = account.getId();
String changeAccountId = account.getId();
String destinationAddress = "3P8xr64WH5vrpH84z2xSeYdhuZXhPDVeY7";
String value = "0.01";
String feeRate = zumoKit.getState().getFeeRates()["BTC"].getAverage();
wallet.sendBtcTransaction(
fromAccountId,
changeAccountId,
destinationAddress,
value,
feeRate,
new SendTransactionCallback() {
@Override
public void onError(Exception e) {
// Transaction not sent. Check exception details
}
@Override
public void onSuccess(Transaction transaction) {
// Transaction submitted
Log.i(TAG, transaction.toString());
}
}
);
NSString *fromAccountId = account.id;
NSString *changeAccountId = account.id;
NSString *destinationAddress = "3P8xr64WH5vrpH84z2xSeYdhuZXhPDVeY7";
NSString *value = "0.01";
NSString *feeRate = [zumoKit getState].feeRates[@"BTC"].average;
[wallet sendBtcTransaction:fromAccountId
changeAccountId:changeAccountId
to:destinationAddress
value:value
feeRate:feeRate
completion:^(ZKTransaction * _Nullable transaction,
NSError * _Nullable error) {
if (error != nil) {
// Something went wrong sending a transaction
NSLog(@"Error authenticating: %@", error.userInfo);
return;
}
// Success! Transaction was submitted to blockchain
NSLog(@"Transaction submitted. Transaction hash: %@", transaction.txHash);
}];
try {
fromAccountId = account.id;
changeAccountId = account.id;
destinationAddress = "3P8xr64WH5vrpH84z2xSeYdhuZXhPDVeY7";
value = "0.01";
feeRate = zumoKit.state.feeRates["BTC"].average;
const transaction = await wallet.sendBtcTransaction(
fromAccountId,
changeAccountId,
destinationAddress,
value,
feeRate
);
} catch(error) {
// Handle error sending transaction here.
}
Ethereum
Select an account as a sender account from the list of user accounts.
Value should be provided in Ethers as a string with dot (.) acting as a decimal separator.
When you submit an Ethereum transaction a fee, gas, has to be paid to miners for transaction confirmation. This fee consists of gas price (fee fate for a unit of gas) and gas limit (maximum units of gas are you willing to spend for transaction confirmation). Maximum acceptable transaction cost, gas, is thus gas price ✕ gas limit and account balance should be more than the value you are sending plus the ammount of gas this transaction might consume, otherwise transaction will be reject by Ethereum nodes.
The faster the fee rate, the faster the transaction will be confirmed. Fee rate can be input manually or one of the suggested fee rates - low, medium or fast - can be used. See Utilities & Helpers for details.
If it is a simple tranfer from one account to another set gas limit to 21000
. More complex transactions, ie. involving smart contract interactions, require gas limit estimations depending on transaction size.
In practice number of gas units consumed will be lower than gas limit as usually not entire gas limit is exhausted.
Data in hexadecimal format starting with 0x can be optionally provided for interaction with smart contracts.
This is experimental functionality and might not work as expected
Nonce, sequential transaction number, can be provided to resubmit transaction with higher gas or overwrite, effectively cancel, a pending transaction. If nonce is not provided, nonce will be automatically set to next transaction nonce.
String fromAccountId = account.getId();
String gasPrice = zumoKit.getState().getFeeRates()["ETH"].getAverage();
String gasLimit = "21000";
String destinationAddress = "0x9B6bDD7f3401B8e66e9Af2d8dCEc4249F4a1f74E";
String value = "0.01";
String data = null;
String nonce = null; // if set to null nonce will be determined automatically
wallet.sendEthTransaction(fromAccountId, gasPrice, gasLimit, destinationAddress, value, data, nonce,
new SendTransactionCallback() {
@Override
public void onError(Exception e) {
// Transaction not sent. Check exception details
}
@Override
public void onSuccess(Transaction transaction) {
// Transaction submitted
Log.i(TAG, transaction.toString());
}
});
});
NSString *fromAccountId = account.id;
NSString *gasPrice = [zumoKit getState].feeRates[@"ETH"].average;
NSString *gasLimit = @"21000";
NSString *destinationAddress = "0x9B6bDD7f3401B8e66e9Af2d8dCEc4249F4a1f74E";
NSString *value = "0.01";
NSString *data = NULL;
NSString *nonce = NULL; // if set to null nonce will be determined automatically
[wallet sendEthTransaction:fromAccountId
gasPrice:gasPrice
gasLimit:gasLimit
to:destinationAddress
value:value
data:data
nonce:nonce
completion:^(ZKTransaction * _Nullable transaction,
NSError * _Nullable error) {
if (error != nil) {
// Something went wrong sending a transaction
NSLog(@"Error authenticating: %@", error.userInfo);
return;
}
// Success! Transaction was submitted to blockchain
NSLog(@"Transaction submitted. Transaction hash: %@", transaction.txHash);
}];
try {
accountId = account.id;
gasPrice = zumoKit.state.feeRates["ETH"].average;;
gasLimit = "21000";
destinationAddress = "0x9B6bDD7f3401B8e66e9Af2d8dCEc4249F4a1f74E";
value = "0.01";
data = null;
nonce = null; // if set to null nonce will be determined automatically
const transaction = await wallet.sendEthTransaction(
accountId,
gasPrice,
gasLimit,
to,
value,
data,
nonce
);
} catch(error) {
// Handle error sending transaction here.
}
Transaction Statuses
Once transaction is submitted it has to be confirmed. This might take variable amount of time depending on the selected fee rate. Once a transaction is confirmed its status will change from pending to confirmed.
Subcribe to transaction changes by attaching a transaction listener to a submitted transaction.
Transaction statuses follow the following order:
- Paused - transaction has been paused by Transaction Service before being submitted to blockchain,
- Pending - transaction has been submitted to blockchain,
- Confirmed / Failed - transaction is either confirmed or rejected,
Ethereum transactions can be resubmitted by sending the same transaction with higher gas price.
Ethereum tarnsactions can be cancelled by sending different transaction with higher gas price than the previously submitted transaction and with with the same nonce as that previously submitted transaction.
For full details see reference (Android / iOS / React Native).