Skip to content

Instantly share code, notes, and snippets.

@munanadi
Last active August 31, 2021 16:11
Show Gist options
  • Select an option

  • Save munanadi/b3137c4c1dbc5eb4492cd7414448a763 to your computer and use it in GitHub Desktop.

Select an option

Save munanadi/b3137c4c1dbc5eb4492cd7414448a763 to your computer and use it in GitHub Desktop.
This works but only for sollet wallet
import { useState, useEffect, useMemo } from "react";
import * as anchor from "@project-serum/anchor";
import { Provider } from "@project-serum/anchor";
import Wallet from "@project-serum/sol-wallet-adapter";
import { PublicKey, Connection } from "@solana/web3.js";
import * as web3 from "@solana/web3.js";
import idl from "./idl.json";
const Home = (props) => {
const [isConnected, setIsConnected] = useState(false);
const programId = new anchor.web3.PublicKey(
"6FZKYLfT1tUPN5CuyqUNWREcr3utyvbn5LR5urSpTqFe"
);
const [provider, wallet, connection] = useMemo(() => {
const opts = {
preflightCommitment: "recent",
commitment: "recent",
};
const network = "http://127.0.0.1:8899";
const wallet = new Wallet("https://www.sollet.io", network);
const connection = new Connection(network, opts.preflightCommitment);
const provider = new Provider(connection, wallet, {
preflightCommitment: "recent",
commitment: "recent",
});
return [provider, wallet, connection];
}, []);
const program = new anchor.Program(idl, programId, provider);
useEffect(() => {
wallet.on("connect", () => {
setIsConnected(true);
});
wallet.on("disconnect", () => {
setIsConnected(false);
});
}, [wallet]);
const toggleState = async () => {
if (!isConnected) {
wallet.connect();
return;
}
// let matchinfo = web3.Keypair.generate();
// let test_ammount = new anchor.BN(10000 * 10000 * 200);
const tx = await program.rpc.dummy({
signers: [],
});
console.log(tx)
};
return (
<div><button onClick={toggleState}>hello</button></div>
);
}
export default Home;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment