Package-level declarations
src/main/kotlin/com/swmansion/starknet/account/Account.kt interface is used to send Starknet transactions for execution. Its base implementation is src/main/kotlin/com/swmansion/starknet/account/StandardAccount.kt.
Example usage of StandardAccount
val provider = JsonRpcProvider("https://your.node.url.com/rpc")
val chainId = provider.getChainId().send()
val address = Felt(0x1234)
val privateKey = Felt(0x1)
val account: Account = StandardAccount(address, privateKey, provider, chainId)
// Execute a single call
val resourceBounds = ResourceBoundsMapping(
l1Gas = ResourceBounds(
maxAmount = Uint64(100_000_000_000),
maxPricePerUnit = Uint128(10_000_000_000_000_000),
),
l2Gas = ResourceBounds(
maxAmount = Uint64(100_000_000_000_000),
maxPricePerUnit = Uint128(1_000_000_000_000_000_000),
),
l1DataGas = ResourceBounds(
maxAmount = Uint64(100_000_000_000),
maxPricePerUnit = Uint128(10_000_000_000_000_000),
),
)
val contractAddress = Felt(0x1111)
val call = Call(contractAddress, "increase_balance", listOf(Felt(100)))
val request = account.executeV3(call, resourceBounds)
val response = request.send()
// Execute multiple calls
val call1 = Call(contractAddress, "increase_balance", listOf(Felt(100)))
val call2 = Call(contractAddress, "increase_balance", listOf(Felt(200)))
account.executeV3(listOf(call1, call2), resourceBounds).send()
// Use automatic maxFee estimation
account.executeV3(call).send()
// or
account.executeV3(call, resourceBounds).send()
// Construct transaction step by step
val otherCall = Call(contractAddress, "increase_balance", listOf(Felt(100)))
val nonce = account.getNonce().send()
val params = InvokeParamsV3(
nonce,
resourceBounds,
)
val signedTransaction = account.signV3(otherCall, params)
val signedInvokeResponse = provider.invokeFunction(signedTransaction).send()
// Sign transaction for fee estimation only
val transactionForFeeEstimation = account.signV3(call, params, true)
// Sign and verify TypedData signature
val typedData = TypedData.fromJsonString("...")
val typedDataSignature = account.signTypedData(typedData)
val isValidSignatureRequest = account.verifyTypedDataSignature(typedData, typedDataSignature)
val isValidSignature = isValidSignatureRequest.send()
// Outside Execution, also known as meta-transactions, allows a protocol to submit transactions on behalf of a
// user account, as long as they have the relevant signatures
val secondAddress = Felt(0x1235)
val secondPrivateKey = Felt(0x2)
val secondAccount = StandardAccount(secondAddress, secondPrivateKey, provider, chainId)
val now = Instant.now()
// create the call for outside execution
val outsideCall1 = account.signOutsideExecutionCallV2(
caller = secondAccount.address,
// transaction can be executed within the following time window
executeAfter = Felt(now.minus(Duration.ofHours(1)).epochSecond),
executeBefore = Felt(now.plus(Duration.ofHours(1)).epochSecond),
calls = listOf(call),
nonce = getOutsideExecutionNonce()
)
// execute the transaction from another account
secondAccount.executeV3(outsideCall1).send()
// create the call for outside execution
val outsideCall2 = account.signOutsideExecutionCallV2(
// transaction can be executed by any caller
caller = Felt.fromShortString("ANY_CALLER"),
// transaction can be executed within the following time window
executeAfter = Felt(now.minus(Duration.ofHours(1)).epochSecond),
executeBefore = Felt(now.plus(Duration.ofHours(1)).epochSecond),
calls = listOf(call1, call2),
nonce = getOutsideExecutionNonce()
)
// execute the transaction from another account
secondAccount.executeV3(outsideCall2).send()
Content copied to clipboard
Types
Link copied to clipboard
Link copied to clipboard
class StandardAccount @JvmOverloads constructor(val address: Felt, signer: Signer, provider: Provider, val chainId: StarknetChainId, cairoVersion: CairoVersion = CairoVersion.ONE) : Account
Standard account used in Starknet.