Send Transaction
To send funds from your wallet to another wallet on the blockchain requires the creation and sending of a transaction. You'll need your unlocked wallet, the address you're sending to, and the funds you wish to send.
Android
To send a transaction on Android, you'll need your previously created or retrieved wallet (Keystore
) and to use the sendTransaction(keystore, address, amount, gasPrice, gasLimit, payload, callback)
method on the WalletManagement
class on your ZumoKit
instance.
The below example demonstrates how to access the WalletManagement
object and send a transaction. Note the two overridden methods in the callback that will provide a transaction or error.
import com.zumo.zumokit.ZumoKit;
import com.zumo.zumokit.WalletManagement;
import com.zumo.zumokit.SendTransactionCallback;
import com.zumo.zumokit.Transaction;
WalletManagement wm = this.zumoKit.walletManagement();
wm.sendTransaction(wallet, "0x123...", "1.00", "40", "21000", "Optional payload", new SendTransactionCallback() {
@Override
public void onError(String message, Transaction txn) {
// Error fetching the transaction!
}
@Override
public void onSuccess(Transaction txn) {
// Transaction obtained successfully!
}
});
iOS
To send a transaction on Android, you'll need your previously created or retrieved wallet (CPKeystore
) and to use the -sendTransaction:toAddress:amount:gasPrice:gasLimit:payload:callback:
method on the CPWalletManagement
class on your ZumoKitImpl
instance.
The below example demonstrates how to access the CPWalletManagement
object and send a transaction.
iOSSendTransactionCallback *callback = [[iOSSendTransactionCallback alloc]
initWithCompletionHandler:^(bool success, NSString * _Nullable errorMessage, CPTransaction * _Nonnull transaction) {
// Called when a response is given from the `sendTransaction` method.
}];
[[_zumoKit walletManagement]
sendTransaction:keystore
toAddress:@"0x123..."
amount:@"1.00"
gasPrice:@"40"
gasLimit:@"21000"
payload:@"Optional payload"
callback:callback];
React Native
The React Native version of ZumoKit uses a method on the Wallet
object you created or retrieved to send a transaction. Providing an address
and amount
to the sendTransaction(address, amount, gasPrice, gasLimit)
method, allows you to send funds in a single line.
The promise will be rejected with a reason should the transaction not be sent. The likely causes for a failure are:
- Wallet was not unlocked
- Insufficient funds
- Network issue
import ZumoKit from 'react-native-zumo-kit';
try {
const wallet = await ZumoKit.getWallet();
const success = await wallet.sendTransaction('0x123...', 1.00, 40, 21000);
} catch(error) {
// Transaction not send successfully
}
// Transaction sent
console.log(success);