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
Parameter
Type
Description
fromAddress
address string
the sender address
toAddress
address string
the smart contract address
data
hex string (0x prefix)
the content of transacting with a smart contract, can use library, such as Web3j, to generate
value (optional)
BigInteger
the amount of Ether deposit in the smart contract (if the smart contract accepts ether)
1
// Create data using web3j
2
val donateFunction = Function(
3
"donate",
4
listOf(Utf8String("Hi, Blocto")),
5
emptyList()
6
)
7
val data = FunctionEncoder.encode(donateFunction)
8
9
// Create value using web3j
10
val value = Convert.toWei("1", Convert.Unit.ETHER).toBigInteger()
11
12
// Send transaction based on specific chain
13
BloctoSDK.[ethereum/bnb/polygon/avalanche].sendTransaction(
14
context = context,
15
fromAddress = fromAddress,
16
toAddress = toAddress,
17
data = data,
18
value = value,
19
onSuccess = { txHash ->
20
// transaction sent
21
},
22
onError = { error ->
23
// handle error
24
}
25
)
Copied!
Copy link