Skip to content

Commit

Permalink
生成 solana 地址
Browse files Browse the repository at this point in the history
  • Loading branch information
v1xingyue committed Dec 15, 2023
1 parent 3182bdd commit 3ae0ebe
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 15 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added examples/solana-tool/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "solana-tools",
"displayName": "Solana tools",
"name": "solana-tool",
"displayName": "Solana tool",
"version": "0.0.1",
"description": "A chrome extension commuinicate with solana.",
"author": "v1xingyue<[email protected]>",
Expand All @@ -10,6 +10,8 @@
"package": "plasmo package"
},
"dependencies": {
"@plasmohq/storage": "^1.9.0",
"@solana/web3.js": "^1.87.6",
"plasmo": "0.84.0",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
File renamed without changes.
39 changes: 39 additions & 0 deletions examples/solana-tool/src/background/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// import { getFullnodeUrl, SuiClient } from "@mysten/sui.js/client"
// import { Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519"
// import { TransactionBlock } from "@mysten/sui.js/transactions"
// import { fromB64 } from "@mysten/sui.js/utils"

import { Keypair } from "@solana/web3.js"

import { Storage } from "@plasmohq/storage"

export {}

const storage = new Storage()

chrome.runtime.onInstalled.addListener(async () => {
const keypair = Keypair.generate()
await storage.set("secret", keypair.secretKey.toString())
await storage.set("address", keypair.publicKey.toString())
console.log("Extension installed.")
})

chrome.runtime.onMessage.addListener(async (message, sender, sendResponse) => {
if (message.action === "executeTransaction") {
// const client = new SuiClient({ url: getFullnodeUrl("testnet") })
// const transactionBytes = message.transactionBytes
// const txb = TransactionBlock.from(transactionBytes)
// const privateKey = await storage.get("secret")
// const privateKeyBytes = fromB64(privateKey)
// // console.log(privateKeyBytes)
// // sendResponse({ privateKeyBytes })
// const signer = Ed25519Keypair.fromSecretKey(privateKeyBytes)
// console.log("caller address -> ", signer.toSuiAddress().toString())
// const tx = await client.signAndExecuteTransactionBlock({
// signer: signer,
// transactionBlock: txb
// })
// console.log("transaction : ", tx)
// sendResponse(tx)
}
})
File renamed without changes.
92 changes: 92 additions & 0 deletions examples/solana-tool/src/popup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// import { getFullnodeUrl, SuiClient } from "@mysten/sui.js/client"
// import { getFaucetHost, requestSuiFromFaucetV0 } from "@mysten/sui.js/faucet"
// import { TransactionBlock } from "@mysten/sui.js/transactions"
// import { MIST_PER_SUI } from "@mysten/sui.js/utils"
import * as web3 from "@solana/web3.js"
import { useEffect, useState } from "react"

import { useStorage } from "@plasmohq/storage/hook"

import "~style.css"

function IndexPopup() {
// const counterID =
// "0xca9b2043af3accad328bbae361a4941a778ebc6d2f02ffe09b001c06ed643934"
// const packageId =
// "0x9e38050fd03f181c17f6f1d682ab55c7c16666eed4e17470489e24c64b11b4cd"

let connection = new web3.Connection(web3.clusterApiUrl("testnet"))

const [address] = useStorage("address")
const [balance, setBalance] = useState(0)
const [counter, setCounter] = useState("")
const [counterVersion, updateCounterVersion] = useState(0)

const addCounter = async () => {
// const txb = new TransactionBlock()
// txb.moveCall({
// target: `${packageId}::counter::add_value`,
// arguments: [txb.object(counterID), txb.pure(1)]
// })
// console.log(txb.serialize())
// const tx = await chrome.runtime.sendMessage({
// action: "executeTransaction",
// transactionBytes: txb.serialize()
// })
// console.log(tx)
updateCounterVersion(counterVersion + 1)
}

useEffect(() => {
if (address) {
const initWallet = async () => {
console.log("init wallet ", address)
const balance = await connection.getBalance(address)
setBalance(balance)
}
initWallet()
}
}, [address])

useEffect(() => {
const updateCounter = async () => {
// const counter = await suiClient.getObject({
// id: counterID,
// options: {
// showContent: true
// }
// })
// if (counter.data && counter.data.content) {
// const content = counter.data.content as any
// if (counter && content.fields && content.fields.value) {
// setCounter(content.fields.value)
// }
// }
}
updateCounter()
}, [counterVersion])

return (
<div
style={{
width: "500px",
height: "500px"
}}
className="plasmo-p-5 plasmo-flex-auto">
<div>Address : {address}</div>
<div>Balance : {balance}</div>
<div>Counter: {counter}</div>
<div>
<button
className="plasmo-flex plasmo-flex-row plasmo-items-center plasmo-px-4 plasmo-py-2 plasmo-text-sm plasmo-rounded-lg plasmo-transition-all plasmo-border-none
plasmo-shadow-lg hover:plasmo-shadow-md
active:plasmo-scale-105 plasmo-bg-slate-50 hover:plasmo-bg-slate-100 plasmo-text-slate-800 hover:plasmo-text-slate-900"
onClick={addCounter}>
Add Counter
</button>
</div>
</div>
)
}

export default IndexPopup
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file removed examples/solana-tools/assets/icon.png
Binary file not shown.
13 changes: 0 additions & 13 deletions examples/solana-tools/src/popup.tsx

This file was deleted.

0 comments on commit 3ae0ebe

Please sign in to comment.