Web3 Core
Multiplatform Web3 Library

⚠️ Experimental
This library is still under development. The library is functional and being used downstream by the likes of SolanaKMP. Breaking changes may will be added leading up to a v1.0 API. You have been warned.
Usage
Solana
Build a Transaction
val account = SolanaPublicKey(keyPair.publicKey)
val memoProgramId = SolanaPublicKey.from("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr")
val memoInstruction = TransactionInstruction(
memoProgramId,
listOf(AccountMeta(account, true, true)),
"hello world ".encodeToByteArray()
)
val blockhash = Blockhash(getRecentBlockhash())
val message = Message.Builder()
.addInstruction(memoInstruction)
.setRecentBlockhash(blockhash)
.build()
Prepare a Signer
using Diglol Crypto library for ED25519 signing:
val keyPair = Ed25519.generateKeyPair()
val signer = object : Ed25519Signer() {
override val publicKey: ByteArray get() = keyPair.publicKey
override suspend fun signPayload(payload: ByteArray): ByteArray = Ed25519.sign(keyPair, payload)
}
Sign Message & Build Transaction
val signature = signer.signPayload(message.serialize())
val transaction = Transaction(listOf(signature), message)
Send Transaction to RPC
Using Base58 encoding from MultiMult and Solana RPC driver from RpcCore
val transactionBytes = transaction.serialize()
val encodedTransaction = Base58.encodeToString(transactionBytes)
val rpcUrl =
rpcDriver = Rpc20Driver(rpcUrl, MyNetworkDriver())
(encodedTransaction: String, requestId: String)
: JsonRpc20Request(
method = ,
params = buildJsonArray {
add(encodedTransaction)
},
requestId
)
requestId =
rpcRequest = SendTransactionRequest(encodedTransaction, requestId)
rpcResponse = rpcDriver.makeRequest(rpcRequest, JsonElement.serializer())
Initiate an SPL Transfer with ATAs