Comments (6)
Awesome!!!
from api.
Transaction sign with Keypair
import {
createTransferCheckedInstruction,
getAssociatedTokenAddress,
getOrCreateAssociatedTokenAccount,
} from "@solana/spl-token";
import { Keypair } from "@solana/web3.js";
const mint = new PublicKey(USDC_MINT_ADDRESS);
const payer = new Keypair()
let instructions: TransactionInstruction[] = [];
const payerATA = await getOrCreateAssociatedTokenAccount(
connection,
payer,
mint,
payer.publicKey
);
const tesouryAcc = await getAssociatedTokenAddress(
mint,
new PublicKey(TESOURY_ACCOUNT)
);
instructionsUsdc.push(
createTransferCheckedInstruction(
payerATA.address,
mint,
tesouryAcc,
payer.publicKey,
payerATA.amount,
6,
[payer]
)
);
const {
blockhash,
lastValidBlockHeight,
} = await connection.getLatestBlockhash();
const messageV0 = new TransactionMessage({
payerKey: payer.publicKey,
recentBlockhash: blockhash,
instructions: instructions,
}).compileToV0Message();
const transaction = new VersionedTransaction(messageV0);
transaction.sign([payer]);
const signature = await connection.sendTransaction(transaction, {
maxRetries: 5,
});
const confirmTransaction = await connection.confirmTransaction(
{
signature: signature,
blockhash,
lastValidBlockHeight,
},
"confirmed"
);
if (confirmTransaction.value.err !== null) return;
from api.
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
import {
PublicKey,
SystemProgram,
SYSVAR_RENT_PUBKEY,
TransactionInstruction
} from "@solana/web3.js";
export const SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID = new PublicKey(
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
);
export function createAssociatedTokenAccountInstruction(
associatedTokenAddress: PublicKey,
payer: PublicKey,
walletAddress: PublicKey,
splTokenMintAddress: PublicKey
) {
const keys = [
{
pubkey: payer,
isSigner: true,
isWritable: true,
},
{
pubkey: associatedTokenAddress,
isSigner: false,
isWritable: true,
},
{
pubkey: walletAddress,
isSigner: false,
isWritable: false,
},
{
pubkey: splTokenMintAddress,
isSigner: false,
isWritable: false,
},
{
pubkey: SystemProgram.programId,
isSigner: false,
isWritable: false,
},
{
pubkey: TOKEN_PROGRAM_ID,
isSigner: false,
isWritable: false,
},
{
pubkey: SYSVAR_RENT_PUBKEY,
isSigner: false,
isWritable: false,
},
];
return new TransactionInstruction({
keys,
programId: SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID,
data: Buffer.from([]),
});
}
Transaction sign with wallet adapter
```ts
import {
createTransferCheckedInstruction,
getAccount,
getAssociatedTokenAddress
} from "@solana/spl-token";
import { createAssociatedTokenAccountInstruction } from "utils/transaction-instruction";
const payerPublicKey = userWallet.publicKey;
const mintPublicKey = new PublicKey(USDC_MINT_ADDRESS);
const recipientPubKey = new PublicKey(recipient.walletAddress);
const ownerATA = await getAssociatedTokenAddress(
mintPublicKey,
payerPublicKey
);
const instructions: TransactionInstruction[] = [];
if (!(await connection.getAccountInfo(ownerATA))) {
instructions.push(
createAssociatedTokenAccountInstruction(
ownerATA,
payerPublicKey,
payerPublicKey,
mintPublicKey
)
);
}
const recipientATA = await getAssociatedTokenAddress(
mintPublicKey,
recipientPubKey
);
if (!(await connection.getAccountInfo(recipientATA))) {
instructions.push(
createAssociatedTokenAccountInstruction(
recipientATA,
payerPublicKey,
recipientPubKey,
mintPublicKey
)
);
}
const totalValue = 100
instructions.push(
createTransferCheckedInstruction(
ownerATA, // from (should be a token account)
mintPublicKey, // mint
recipientATA, // to (should be a token account)
payerPublicKey, // from's owner
new BN(totalValue * 1000000), // 1000_000 6 decimals place need get custom for each SPL token
6
)
);
const { blockhash } = await connection.getLatestBlockhash();
const solanaTransaction = new Transaction().add(...instructions);
solanaTransaction.recentBlockhash = blockhash;
solanaTransaction.feePayer = payerPublicKey;
solanaTransaction.instructions = instructions;
const transaction = await userWallet.signTransaction(solanaTransaction);
const newTransaction = transaction.serialize();
const signature = await connection.sendRawTransaction(newTransaction);
from api.
Sign Message
Sign Message with wallet adapter
const VERIFY_USER = `DFXswiss`
const signature = await wallet.signMessage(VERIFY_USER)
const serializedSignature = bs58.encode(signature);
Verify Message
const VERIFY_USER = `DFXswiss`
const verifyMessage = sign.detached.verify(
new TextEncoder().encode(VERIFY_USER),
bs58.decode(sigDecrypted),
new PublicKey(user.walletAddress).toBytes()
);
from api.
Wallet Connet
import {
ConnectionProvider,
WalletProvider
} from "@solana/wallet-adapter-react";
import { WalletModalProvider } from "@solana/wallet-adapter-react-ui";
import { PhantomWalletAdapter } from "@solana/wallet-adapter-wallets";
const wallets = useMemo(() => [new PhantomWalletAdapter()], []); // You can put some here like Backpack, etc..
const connection = useMemo(() => new Connection(HELIUS_API), []);
<ConnectionProvider endpoint={RPC}>
<WalletProvider wallets={wallets} autoConnect>
<WalletModalProvider>{children}</WalletModalProvider>
</WalletProvider>
</ConnectionProvider>
import { useWallet } from "@solana/wallet-adapter-react";
const wallet = useWallet();
wallet.connect(); // Show Modal with the wallets
from api.
Hi @dannpl
Thank you very much for your support!
We have decided to integrate Solana as soon as we have a large Soalana wallet that integrates us.
If you can help us with this, please reply to this message. In the meantime, I will close this issue.
from api.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from api.