Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions embedded-wallets/connect-blockchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ image: 'img/metamaskog.jpg'
import EVMChains from './\_evm-chains.mdx'
import OtherChains from './\_other-chains.mdx'

Embedded Wallets (formerly Web3Auth) is the frontend authentication system for your dApp. Once the user is authenticated, the SDK returns a way to interact with the blockchain. A provider is how libraries like web3.js & ethers.js talk to the blockchain by sending JSON-RPC requests and receiving responses.
Embedded Wallets is the frontend authentication system for your dApp. Once the user is authenticated, the SDK returns a way to interact with the blockchain. A provider is how libraries like web3.js & ethers.js talk to the blockchain by sending JSON-RPC requests and receiving responses.

With Embedded Wallets, you can connect in two ways:

Expand All @@ -22,7 +22,7 @@ The SDKs are now branded as MetaMask Embedded Wallet SDKs (formerly Web3Auth Plu

::::

## Dashboard Configuration
## Dashboard configuration

The Embedded Wallets Web SDK (`@web3auth/modal`) from v10 onwards does not need any additional setup on the code side for blockchain connections. All of it is handled on the Dashboard. We can use any chain from the extensive list of predefined chains and add more if we need.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Once user has successfully logged in, you can retrieve the user's private key using the `getPrivKey` method from the Embedded Wallets Android SDK (formerly Web3Auth). We'll use this private key to generate the Credentials for the user.
Once user has successfully logged in, you can retrieve the user's private key using the `getPrivKey` method from the Embedded Wallets Android SDK. We'll use this private key to generate the Credentials for the user.

This Credentials object has the user's key pair of private key and public key, and can be used to sign the transactions. Please note, that this assumes that the user has already logged in and the private key is available.
This Credentials object has the user's keypair of private key and public key, and can be used to sign the transactions. Please note, that this assumes that the user has already logged in and the private key is available.

```kotlin
import org.web3j.crypto.Credentials
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
To retrieve the native balance of the user, you can use the `Web3j` instance we created earlier. It
has `ethGetBalance` method which helps to fetch the user's native token balance.
has `ethGetBalance` method which fetches the user's native token balance.

The result we get from method is in wei, the smallest value. To convert the value to ether, you can
divide it with 10^18, where 18 denotes the decimals for wei.
The result we get from Web3Client is in wei, the smallest unit of ether. To convert wei to ether, divide by 10^18, where 18 denotes the decimals for wei.

```kotlin
import org.web3j.protocol.core.DefaultBlockParameterName

// Use the existing Web3j instance, and address from the previous step
val balanceResponse = web3.ethGetBalance(address, DefaultBlockParameterName.LATEST).send()

// Convert the balance from Wei to Ether format
// Convert the balance from wei to ether format
val ethBalance = BigDecimal.valueOf(balanceResponse.balance.toDouble()).divide(BigDecimal.TEN.pow(18))
```
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
We'll initialize the Web3j instance with the RPC URL of the network you want to connect to. This
client allows us to interact with the blockchain. To get the public RPC URL, you can checkout
client allows us to interact with the blockchain. To get the public RPC URL, see
[ChainList](https://chainlist.org/).

```kotlin
import org.web3j.protocol.Web3j
import org.web3j.protocol.http.HttpService

// Please avoid using public RPC URL in production, use services
// like Infura, Quicknode, etc.
// like Infura.
val web3 = Web3j.build(HttpService("YOUR_RPC_URL"))
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
To interact with the Ethereum Compatible Blockchain in Android, you can use any [`EIP1193`](https://eips.ethereum.org/EIPS/eip-1193) compatible package available for Android. Here we're using [web3j](https://github.com/web3j/web3j) to demonstrate how to make blockchain calls using it with Embedded Wallets (formerly Web3Auth).
To interact with Ethereum in Android, you can use any [`EIP1193`](https://eips.ethereum.org/EIPS/eip-1193)-compatible package available for Android. Here we're using [web3j](https://github.com/web3j/web3j) to demonstrate how to make blockchain calls using it with Embedded Wallets.

```groovy
dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ This doc assumes you have already setup your project in the Embedded Wallets Das

<InitialisationSnippet />

## Get Account
## Get account

<GetAccountSnippet />

## Get Balance
## Get balance

<GetBalanceSnippet />

## Sign a message

<SignMessageSnippet />

## Send Transaction
## Send transaction

<SendTransactionSnippet />
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
To send a transaction, you can use the `Web3j` instance we created earlier. It has
`ethSendRawTransaction` method which helps to send the raw transaction to the network. To create a
raw transaction, you need to retrieve nonce, gas price, gas limit, and the value of the transaction.
The nonce is the number of transactions sent from the sender's address. The gas price is the price
of the gas, which is the unit of account for the transaction. The gas limit is the maximum amount of
gas that the sender is willing to pay for the transaction. The value is the amount of ether to send.

The default gas limit for a transfer ETH transaction is 21000, but you can also estimate the gas
limit explicitly using `ethEstimateGas` method.
`ethSendRawTransaction` method which sends the raw transaction to the network. To create a
raw transaction, you need to retrieve nonce, gas price, gas limit, and the value of the transaction:

- nonce is the number of transactions sent from the sender's address
- gas price is the unit of account for the transaction
- gas limit is the maximum amount of gas that the sender is willing to pay for the transaction

The gas values are in ether. The default gas limit for a transfer ETH transaction is 21000, but you can
also estimate the gas limit explicitly using `ethEstimateGas` method.

```kotlin
import org.web3j.protocol.core.methods.response.EthGetTransactionCount
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
To sign the message, you need to use the `Sign.signPrefixedMessage` method. The method takes in the
data of the message, ecKeyPair, and returns the Signature object which has r, s and v value of the
data of the message, ecKeyPair, and returns the Signature object which has `r`, `s` and `v` value of the
signature.

We can append the r, s, and v values to generate the signed hash. The r value is the first 32 bytes
of the signature, s is the next 32 bytes, and v is the last 1 byte of the signature.
We can append the `r`, `s`, and `v` values to generate the signed hash. The `r` value is the first 32 bytes
of the signature, `s` is the next 32 bytes, and `v` is the last 1 byte of the signature.

```kotlin
import org.web3j.utils.Numeric
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Since web3dart package doesn't support deploying contracts directly, we'll use the precompiled smart
contract byteCode to deploy the contract using `sendTransaction` method.
Since the web3dart package doesn't support deploying contracts directly, we'll use the precompiled smart
contract byteCode to deploy the contract using the `sendTransaction` method.

```dart
// Use the client, address, and credentials from previous code snippets
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Once user has successfully logged in, you can retrieve the user's private key using the `getPrivKey` method from the Embedded Wallets Flutter SDK (formerly Web3Auth). We'll use this private key to generate the Credentials for the user.
Once the user has successfully logged in, you can retrieve the user's private key using the `getPrivKey` method from the Embedded Wallets Flutter SDK. We'll use this private key to generate the Credentials for the user.

This Credentials object has the user's key pair of private key and public key, and can be used to sign the transactions. Please note, that this assumes that the user has already logged in and the private key is available.
This Credentials object has the user's keypair of private key and public key, and can be used to sign the transactions. Please note, that this assumes that the user has already logged in and the private key is available.

```dart
import 'package:web3dart/web3dart.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
To retrieve the native balance of the user, you can use the `Web3Client` object we created earlier.
It has `getBalance` method which helps to fetch the user's native token balance.

The result we get from Web3Client is in wei, the smallest value. To convert the value to ether, you
can divide it with 10^18, where 18 denotes the decimals for wei.
The result we get from Web3Client is in wei, the smallest unit of ether. To convert wei to ether, divide by 10^18, where 18 denotes the decimals for wei.

For the simplicity, we'll use a helper function from web3dart package which has the same
implementation
For the simplicity, we'll use a helper function from web3dart package which implements this conversion:

```dart
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
We'll initialize the `Web3Client` with the RPC URL of the network you want to connect to. This
client allows us to interact with the blockchain. To get the public RPC URL, you can checkout
[chainlist.org](https://chainlist.org/).
client allows us to interact with the blockchain. To get the public RPC URL, see
[Chainlist.org](https://chainlist.org/).

```dart
import 'package:web3dart/web3dart.dart';

// Please avoid using public RPC URL in production, use services
// like Infura, Quicknode, etc.
// like Infura.
final client = Web3Client("YOUR_RPC_URL", Client());
```
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import TabItem from '@theme/TabItem'
import Tabs from '@theme/Tabs'

To interact with the Ethereum compatible blockchains in Flutter, you can use any [`EIP1193`](https://eips.ethereum.org/EIPS/eip-1193) compatible package. Here, we're using [web3dart](https://pub.dev/packages/web3dart) to demonstrate how to make blockchain calls using it with Embedded Wallets (formerly Web3Auth).
To interact with the Ethereum compatible blockchains in Flutter, you can use any [`EIP1193`](https://eips.ethereum.org/EIPS/eip-1193) compatible package. Here, we're using [web3dart](https://pub.dev/packages/web3dart) to demonstrate how to make blockchain calls using it with Embedded Wallets.

To install the `web3dart` package, you have two options. You can either manually add the package in the `pubspec.yaml` file, or you can use the `flutter pub add` command.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ This doc assumes you have already setup your project in the Embedded Wallets Das

<InitialisationSnippet />

## Get Account
## Get account

<GetAccountSnippet />

## Get Balance
## Get balance

<GetBalanceSnippet />

## Sign Transaction

<SignTransactionSnippet />

## Send Transaction
## Send transaction

<SendTransactionSnippet />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
To interact with any smart contract, you need the contract address and the ABI of the contract. The
ABI of the contract helps encode the function name and its parameters. Considering ABI as a outline
ABI of the contract helps encode the function name and its parameters. Consideri ABI as an outline
of the contract, which provides contract specifications.

We'll create a `DeployedContract` instance with the contract address and ABI. Once created, we can
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
If you wish to sign, and also broadcast the transaction, you can use the
If you wish to sign *and* broadcast the transaction, you can use the
`Web3Client.sendTransaction` method.

This method prepares the transaction, and signs similar to `signTransaction` method. The only
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
To sign a transaction, you can use the `Web3Client` object we created earlier. It has
`signTransaction` method which helps to sign the transaction for the given key pair, and chain.
`signTransaction` method which signs the transaction for the given key pair, and chain.

The method internally handles the nonce, gas price, and gas limit. If you want to manually set the
nonce, gas price, and gas limit, you can override the parameters in the Transaction object.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
With the web3dart library, apart from doing the normal interactions, and transactions, you can also
In addition to the intetactions and transactions, the web3dart library allows you to
deploy and interact with Smart Contracts.

Firstly, we'll create a new smart contract using Solidity that allows to store a message and update
Firstly, we'll create a new smart contract using Solidity that allows us to store a message and update
it. The contract will have a constructor that takes an initial message as input, and a function to
update the message.

Expand All @@ -22,14 +22,14 @@ contract HelloWorld {
}
```

The package don't have a way to compile solidity smart contracts, so we'll need to compile the
contract using an online compiler and get the bytecode and abi from there. For this example we'll
The package don't have a way to compile Solidity smart contracts, so we'll need to compile the
contract using an online compiler and get the bytecode and ABI from there. For this example we'll
use [Remix IDE](https://remix.ethereum.org/) to compile the contract.

Please note that the bytecode and abi are different for each network, so you'll need to compile the
Please note that the bytecode and ABI are different for each network, so you'll need to compile the
contract for the network you want to deploy it to.

Once compiled, please copy the bytecode and abi for the future usecases.
Once compiled, please copy the bytecode and ABI for the future usecases.

```dart
final contractAbi = '[{"constant":false,"inputs":[{"name":"newMessage","type":"string"}],"name":"update","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"message","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"initMessage","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Similary, you can write to the contract using the `sendTransaction` method of Web3Client. In this
Similary, you can write to the contract using the `sendTransaction` method supported by Web3Client. In this
sample, we'll update the message in the contract we deployed previously.

```dart
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Post V10 release, Web3Auth Web SDK does not need any additional setup on the code side for other
chains. All is handled on the Dashboard.
Post v10 release, Web3Auth Web SDK does not need any additional setup on the code side for other
chains: everything is handled on the Dashboard.

```tsx
import { Web3Auth, WEB3AUTH_NETWORK } from "@web3auth/modal";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
To retrieve the user's Ethereum address, you can use the `EthereumAccount` class. This account can
Use the `EthereumAccount` class to retrieve the user's Ethereum address. This account can
also be used to sign transactions and messages.

The package doesn't provides any direct way to consume the the private key and create an account.
Expand All @@ -24,7 +24,7 @@ extension Web3AuthState: EthereumSingleKeyStorageProtocol {
}
```

Once we have created the extension, we can use the Web3AuthState to create an EthereumAccount.
Once we have created the extension, we can use the Web3AuthState to create an `EthereumAccount`.
Please note, that this assumes that the user has already logged in and the state is available.

```swift
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
To retrieve the balance of an Ethereum address, you can use the `EthereumClient.eth_getBalance`
method. The response we get from this method is in Wei, so we need to convert it to Ether. The get
the ether value, you can divide the wei value with `1 / 10^18`.
Use the `EthereumClient.eth_getBalance` method to retrieve the balance of an Ethereum address.

The result we get from Web3Client is in wei, the smallest unit of ether. To convert wei to ether, divide by 10^18, where 18 denotes the decimals for wei.

```swift
import web3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
To interact with the blockchain, initialize the `EthereumHttpClient` with the RPC URL, and chain id
of the network you want to connect to. To get the public RPC URL, and other details as chain id, you
can checkout [ChainList](https://chainlist.org/).
Initialize the `EthereumHttpClient` with the RPC URL and chain id
of the network you want to connect to, to interact with the blockchain. To get the public RPC URL, and other details as chain id, see [ChainList](https://chainlist.org/).

```swift
import web3

let client = EthereumHttpClient(
// Please avoid using public RPC URL in production, use services
// like Infura, Quicknode, etc.
// like Infura.
url: URL.init(string: rpcUrl)!,
// Replace with the chain id of the network you want to connect to
network: .custom(chainId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ This doc assumes you have already setup your project in Web3Auth Dashboard, and

<InitialisationSnippet />

## Get Account
## Get account

<GetAccountSnippet />

## Get Balance
## Get balance

<GetBalanceSnippet />

## Sign a message

<SignMessageSnippet />

## Send Transaction
## Send transaction

<SendTransactionSnippet />
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
For signing and sending the transaction, we'll create helper methods to get the nonce, gas price,
estimate the gas and send the transaction. The nonce is the number of transactions sent from the
address. The gas price is the price of the gas in Wei. The gas limit is the maximum amount of gas
that can be used to send the transaction. Apart form that, we'll also create a helper method to
convert the amount to Wei.
estimate the gas and send the transaction:

- nonce is the number of transactions sent from the sender's address
- gas price is the unit of account for the transaction
- gas limit is the maximum amount of gas that the sender is willing to pay for the transaction

The gas values are in ether. We'll also create a helper method to convert the amount to wei.

Once the transaction object is created, we'll estimate the gas and create a new transaction object
with the gas limit. Finally, we'll send the transaction using
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import SignMessageSnippet from './_evm-sign-message.mdx'

<InitialisationSnippet />

## Get Account
## Get account

<GetAccountSnippet />

## Get Balance
## Get balance

<GetBalanceSnippet />

Expand Down
2 changes: 1 addition & 1 deletion embedded-wallets/connect-blockchain/_other-chains.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const OtherChains = [
},
{
key: 'starknet',
title: 'StarkNet',
title: 'Starknet',
icon: 'logo-starknet.png',
path: '/embedded-wallets/connect-blockchain/other/starknet',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
To interact with an EVM blockchain in React Native, you can use any [`EIP1193`](https://eips.ethereum.org/EIPS/eip-1193) compatible package like
[`web3.js`](https://web3js.readthedocs.io/en/v1.2.8/getting-started.html), [`ethers.js`](https://docs.ethers.io/v5/getting-started/) etc.
To interact with an EVM blockchain in React Native, you can use any [`EIP1193`](https://eips.ethereum.org/EIPS/eip-1193) compatible package such as
[`web3.js`](https://web3js.readthedocs.io/en/v1.2.8/getting-started.html) or [`ethers.js`](https://docs.ethers.io/v5/getting-started/).

In this reference, we're using `ethers.js` to demonstrate how to make blockchain calls using it with Web3Auth.
In this example, we use `ethers.js` to demonstrate how to make blockchain calls using it with Web3Auth.

- Install the `ethers.js` package using `npm` or `yarn`:

Expand All @@ -21,7 +21,6 @@ import { ethers } from "ethers";

:::info

We have followed [this guide](https://docs.ethers.org/v5/cookbook/react-native/#cookbook-reactnative) to set up the `ethers.js` package in React
Native.
We have followed [this guide](https://docs.ethers.org/v5/cookbook/react-native/#cookbook-reactnative) to set up the `ethers.js` package in React Native.

:::
Loading
Loading