What is @coinbase/wallet-sdk?
@coinbase/wallet-sdk is a JavaScript library that allows developers to integrate Coinbase Wallet into their web applications. It provides functionalities for connecting to the wallet, managing user accounts, and interacting with the Ethereum blockchain.
What are @coinbase/wallet-sdk's main functionalities?
Connect to Coinbase Wallet
This feature allows you to connect to the Coinbase Wallet. You can specify the app name, logo URL, and whether to use dark mode. The `makeWeb3Provider` method creates a Web3 provider instance connected to the Ethereum mainnet.
const { CoinbaseWalletSDK } = require('@coinbase/wallet-sdk');
const wallet = new CoinbaseWalletSDK({ appName: 'My App', appLogoUrl: 'https://example.com/logo.png', darkMode: false });
const ethereum = wallet.makeWeb3Provider('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID', 1);
Request Account Access
This feature allows you to request access to the user's Ethereum accounts. The `eth_requestAccounts` method prompts the user to connect their wallet and grants access to their accounts.
ethereum.request({ method: 'eth_requestAccounts' }).then(accounts => {
console.log(accounts);
}).catch(error => {
console.error(error);
});
Send Transactions
This feature allows you to send transactions from the connected wallet. You can specify the recipient address, sender address, value, and gas limit. The `eth_sendTransaction` method sends the transaction and returns the transaction hash.
const transactionParameters = {
to: '0xRecipientAddress',
from: '0xYourAddress',
value: '0x29a2241af62c0000', // 0.1 ETH
gas: '0x5208', // 21000 GWEI
};
ethereum.request({ method: 'eth_sendTransaction', params: [transactionParameters] }).then(txHash => {
console.log(txHash);
}).catch(error => {
console.error(error);
});
Other packages similar to @coinbase/wallet-sdk
web3
Web3.js is a collection of libraries that allow you to interact with a local or remote Ethereum node using HTTP, IPC, or WebSocket. It provides functionalities for sending transactions, interacting with smart contracts, and more. Compared to @coinbase/wallet-sdk, Web3.js is more general-purpose and can be used with various Ethereum wallets and providers.
ethers
Ethers.js is a library for interacting with the Ethereum blockchain and its ecosystem. It provides a concise and consistent interface for sending transactions, interacting with smart contracts, and more. Ethers.js is known for its simplicity and ease of use, making it a popular choice among developers. Unlike @coinbase/wallet-sdk, it is not specific to Coinbase Wallet and can be used with various providers.
walletconnect
WalletConnect is an open protocol for connecting desktop DApps to mobile wallets using end-to-end encryption by scanning a QR code. It supports multiple wallets and provides a secure way to connect and interact with decentralized applications. Compared to @coinbase/wallet-sdk, WalletConnect offers broader wallet compatibility and focuses on secure connections between DApps and mobile wallets.
Coinbase Wallet SDK
Coinbase Wallet SDK (formerly WalletLink) lets developers connect their dapps to Coinbase Wallet
on both mobile web (for iOS and Android) and desktop:
Wallet SDK is open-source and uses minimal dependencies for maximum security and no code bloat. Simply drop a few lines of code into your dapp and Wallet SDK takes care of the rest.
Getting started
Installing and Upgrading
The installation package for Coinbase Wallet SDK (formerly WalletLink) is now named @coinbase/wallet-sdk
.
Installing Wallet SDK
Install Coinbase Wallet SDK with yarn or npm.
Yarn
- Check available versions of Wallet SDK.
yarn info @coinbase/wallet-sdk versions
- Install a specific version or the latest version.
#yarn add @coinbase/wallet-sdk@3.0.0
yarn add @coinbase/wallet-sdk
- Check your installed version.
yarn list @coinbase/wallet-sdk
Npm
- Check available versions of Wallet SDK.
npm view @coinbase/wallet-sdk versions
- Install a specific version or the latest version.
#npm install @coinbase/wallet-sdk@3.0.0
npm install @coinbase/wallet-sdk
- Check your installed version.
npm list @coinbase/wallet-sdk
Upgrading Wallet SDK
Upgrade Coinbase Wallet SDK with yarn or npm.
Yarn
- Compare your installed version of Coinbase Wallet SDK with the latest available version.
yarn outdated @coinbase/wallet-sdk
- Update Coinbase Wallet SDK to the latest.
yarn upgrade @coinbase/wallet-sdk --latest
Npm
- Compare your installed version of Coinbase Wallet SDK with the latest available version.
npm outdated @coinbase/wallet-sdk
- If necessary, update
package.json
with the latest major version.
{
"dependencies": {
"@coinbase/wallet-sdk": "^3.0.0"
}
}
- Update Coinbase Wallet SDK to the latest available version.
npm update @coinbase/wallet-sdk
Libraries using Coinbase Wallet SDK
Copyright © 2018-2022 Coinbase, Inc. <https://www.coinbase.com/>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Attributions