Hey all,
let me know what you think about this SNIP I have been working on. Glad to receive feedback and suggestions!
Thanks, Janek!
Standardizing Starknet Wallet Connections with Write API and JSON-RPC Integration
snip: tbd
title: Standardizing Starknet Wallet Connections with Write API and JSON-RPC Integration
status: Draft
type: Standard
author: Janek Rahrt <janek@argent.xyz>
created: 2023-08-01
Simple Summary
A proposal to integrate Starknet Write API and wallet RPC methods, aligning the connection method closer to how Ethereum handles wallet connections, and solving the versioning problems currently faced by using starknet.js.
Abstract
This SNIP proposes a new way of connecting wallets with dapps in the Starknet ecosystem by using RPC methods, specifically integrating the methods described in Starknet Write API and wallet-specific methods, pioneered by metamask.
Motivation
The current method of exposing an interface from starknet.js to the webpage has led to problems with versioning. The coupling makes integrations more fragile and starknet.js versioning is a slow and painful process. This proposal aims to standardize the wallet connection process, making it more robust and maintainable, and decouple it from the developments in starknet.js. It will also allow for more competing starknet wallet libraries, such as viem forks etc.
Specification
Using RPC for Starknet wallet connections (1)
- Starknet will utilize a similar approach to Ethereum’s
window.ethereum.request()
method for making RPC calls. - Developers can interact with Starknet by calling a method such as
window.starknet.request()
, passing in the specific method name and parameters. - This approach allows for a consistent and standardized way to interact with Starknet, aligning with how Ethereum handles wallet connections.
Wallet JSON-RPC API Integration (2)
- Utilize Wallet’s Ethereum JSON-RPC API methods.
- Implement methods including:
wallet_requestAccounts
: Replaces the.enable()
method and returns an array with the activated account address. This method prompts the user to allow the dapp to read the account address.wallet_addStarknetChain
: Allows the user to add a specific Starknet chain to the wallet. This method creates a confirmation asking the user to add the specified chain, and the user may choose to switch to the chain once it has been added.wallet_switchStarknetChain
: Enables the user to switch to a different Starknet chain within the wallet. This method creates a confirmation asking the user to switch to the chain with the specified chain ID.wallet_watchAsset
: Enables the user to track specific assets within Starknet ecosystem, such as ERC-20 tokens or NFTs. This method requests that the user track the specified asset in their wallet.- If needed, these methods can be extended by some EIP-2255 style enhancements.
- Handle specific errors such as
RPCErrors
etc.
Starknet Write API Integration (3)
- Implement Starknet Write API methods, including:
starknet_addInvokeTransaction
: Submit a new transaction to be added to the chain. User will need to confirm in the wallet.starknet_addDeclareTransaction
: Submit a new class declaration transaction. User will need to confirm in the wallet.starknet_addDeployAccountTransaction
: Submit a new deploy account transaction. User will need to confirm in the wallet.
- Handle specific errors such as
INSUFFICIENT_ACCOUNT_BALANCE
,INVALID_TRANSACTION_NONCE
, etc.
Additional Starknet API
- Implement some methods that are not covered by
wallet_
methods or by the Starknet Write APIstarknet_signTypedData
: Sign a eip-712 like message. User will need to confirm in the wallet.
Implementation
The implementation of this SNIP will require the following steps:
- Integration with Wallet JSON-RPC API: Adapt Wallet’s JSON-RPC API methods for Starknet.
- Integration with Starknet Write API: Implement the methods described in Starknet Write API.
- Testing: Conduct thorough testing to ensure compatibility and robustness.
- Documentation: Update the documentation to reflect the new connection method.
- Deployment: Roll out the changes to the Starknet ecosystem.
Links
Examples
Example 1: Requesting Starknet Accounts
window.starknet.request({ method: 'wallet_requestAccounts' }).then(accounts => {
console.log(accounts);
});
Example 2: Adding a Starknet Chain
window.starknet.request({ method: 'wallet_addStarknetChain', params: [chainDetails] }).then(result => {
console.log(result);
});
History
This proposal is a response to the ongoing challenges with versioning and the need for a more standardized way to connect wallets in the Starknet ecosystem. Prior efforts to address this issue were restricted by the limitations of the existing starknet.js interface.
Copyright
Copyright and related rights waived via MIT.