generated from scaffold-eth/scaffold-eth-2
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from dynamic-labs/feat/sign-message-example
feat: add basic sign message and send transaction
- Loading branch information
Showing
4 changed files
with
170 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Wallet } from "@dynamic-labs/sdk-react-core"; | ||
import { getOrMapViemChain } from "@dynamic-labs/viem-utils"; | ||
import { Account, Chain, Hex, Transport, WalletClient, parseEther } from "viem"; | ||
import { customEvmNetworks } from "~~/lib/networks"; | ||
|
||
export const signMessage = async (message: string, wallet: any): Promise<string> => { | ||
const connector = wallet?.connector; | ||
|
||
return await connector.signMessage(message); | ||
}; | ||
|
||
export const sendTransaction = async (address: any, amount: string, wallet: Wallet): Promise<string> => { | ||
const walletClient = wallet.connector.getWalletClient<WalletClient<Transport, Chain, Account>>(); | ||
|
||
const chainID = await wallet.connector.getNetwork(); | ||
const currentNetwork = customEvmNetworks.find(network => network.chainId === chainID); | ||
|
||
if (!currentNetwork) { | ||
throw new Error("No chain ID found"); | ||
} | ||
|
||
const chain = getOrMapViemChain(currentNetwork); | ||
|
||
const transaction = { | ||
account: wallet.address as Hex, | ||
to: address as Hex, | ||
chain, | ||
value: amount ? parseEther(amount) : undefined, | ||
}; | ||
|
||
const transactionHash = await walletClient.sendTransaction(transaction); | ||
return transactionHash; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
export const customEvmNetworks = [ | ||
{ | ||
blockExplorerUrls: ["http://localhost"], | ||
chainId: 43490458484, | ||
chainName: "My Arbitrum L3 Chain", | ||
iconUrls: ["https://www.shutterstock.com/image-vector/moon-icon-vector-star-logo-600nw-1403123270.jpg"], | ||
name: "My Arbitrum L3 Chain", | ||
nativeCurrency: { | ||
decimals: 18, | ||
name: "Ether", | ||
symbol: "ETH", | ||
}, | ||
networkId: 43490458484, | ||
|
||
rpcUrls: ["http://127.0.0.1:8449"], | ||
vanityName: "Into Orbit", | ||
}, | ||
{ | ||
blockExplorerUrls: ["https://explorer-holesky.morphl2.io/"], | ||
chainId: 2810, | ||
name: "Morph", | ||
rpcUrls: ["https://rpc-quicknode-holesky.morphl2.io"], | ||
iconUrls: ["https://avatars.githubusercontent.com/u/132543920?v=4"], | ||
nativeCurrency: { | ||
name: "Ethereum", | ||
symbol: "ETH", | ||
decimals: 18, | ||
}, | ||
networkId: 2810, | ||
}, | ||
{ | ||
blockExplorerUrls: ["https://explorer.zircuit.com"], | ||
chainId: 48899, | ||
name: "Zircuit Testnet", | ||
rpcUrls: ["https://zircuit1.p2pify.com/"], | ||
iconUrls: ["https://pbs.twimg.com/profile_images/1774812048683143168/gSbmfQfa_400x400.jpg"], | ||
nativeCurrency: { | ||
name: "Ethereum", | ||
symbol: "ETH", | ||
decimals: 18, | ||
}, | ||
networkId: 48899, | ||
}, | ||
{ | ||
blockExplorerUrls: ["https://explorer.zero.network"], | ||
chainId: 4457845, | ||
name: "ZERϴ", | ||
rpcUrls: ["https://rpc.zerion.io/v1/zero-sepolia"], | ||
iconUrls: ["https://pbs.twimg.com/profile_images/1805906049213329408/oZFUGW9L_400x400.jpg"], | ||
nativeCurrency: { | ||
name: "Ethereum", | ||
symbol: "ETH", | ||
decimals: 18, | ||
}, | ||
networkId: 4457845, | ||
}, | ||
{ | ||
blockExplorerUrls: ["https://explorer.testnet.rsk.co"], | ||
chainId: 31, | ||
name: "RSK Testnet", | ||
rpcUrls: ["https://public-node.testnet.rsk.co"], | ||
iconUrls: ["https://rootstock.io/icons/icon-512x512.png?v=d5199ca8e8f274bc01b19fe9024f128e"], | ||
nativeCurrency: { | ||
name: "Rootstock Bitcoin", | ||
symbol: "tRBTC", | ||
decimals: 18, | ||
}, | ||
networkId: 31, | ||
}, | ||
{ | ||
blockExplorerUrls: ["https://explorer.rsk.co"], | ||
chainId: 30, | ||
name: "RSK Mainnet", | ||
rpcUrls: ["https://public-node.rsk.co"], | ||
iconUrls: ["https://rootstock.io/icons/icon-512x512.png?v=d5199ca8e8f274bc01b19fe9024f128e"], | ||
nativeCurrency: { | ||
name: "Rootstock Bitcoin", | ||
symbol: "tRBTC", | ||
decimals: 18, | ||
}, | ||
networkId: 30, | ||
}, | ||
]; |