Send Transaction

Make sure you initialize Blocto SDK first

Once your app is connected to Blocto wallet, it can send transactions on behalf of the user, with the user's permission.

In order to send a transaction, the app needs to:

  • Create data which is the content of transacting with a smart contract

  • Create value if needs to send the Ether to smart contract

// Create data using web3j
val donateFunction = Function(
    "donate", 
    listOf(Utf8String("Hi, Blocto")), 
    emptyList()
)
val data = FunctionEncoder.encode(donateFunction)

// Create value using web3j
val value = Convert.toWei("1", Convert.Unit.ETHER).toBigInteger()

// Send transaction based on specific chain
BloctoSDK.evm.sendTransaction(
    context = context,
    blockchain = Blockchain.ETHEREUM,
    fromAddress = fromAddress,
    toAddress = toAddress,
    data = data,
    value = value,
    onSuccess = { txHash ->
        // transaction sent
    },
    onError = { error ->
        // handle error
    }
)

Last updated