-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
1,236 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Import Push Chain SDK | ||
import { CONSTANTS, PushChain } from '@pushchain/devnet'; | ||
// Import utility functions from viem | ||
import { hexToBytes } from 'viem'; | ||
import { privateKeyToAccount, generatePrivateKey } from 'viem/accounts'; | ||
|
||
// Generate Private Key | ||
const privateKey = generatePrivateKey(); | ||
const account = privateKeyToAccount(privateKey); | ||
|
||
// Create signer. This is the signer that will be used to sign the transaction. | ||
const signer = { | ||
chain: CONSTANTS.CHAIN.ETHEREUM, | ||
chainId: CONSTANTS.CHAIN_ID.ETHEREUM.SEPOLIA, | ||
address: account.address, // Ethereum address derived from the private key | ||
signMessage: async (data) => { | ||
const signature = await account.signMessage({ | ||
message: { raw: data }, // Data to be signed | ||
}); | ||
return hexToBytes(signature); // Convert signature to a byte array | ||
}, | ||
}; | ||
|
||
// Initialize Push Chain SDK | ||
const pushChain = await PushChain.initialize(signer); | ||
|
||
// Send Transaction | ||
const tx = await pushChain.tx.send( | ||
[ | ||
{ | ||
chain: CONSTANTS.CHAIN.SOLANA, | ||
chainId: CONSTANTS.CHAIN_ID.SOLANA.DEVNET, | ||
account: 'ySYrGNLLJSK9hvGGpoxg8TzWfRe8ftBtDSMECtx2eJR', | ||
}, | ||
], | ||
{ | ||
category: 'MY_CUSTOM_CATEGORY', | ||
data: JSON.stringify({ | ||
title: 'Hello old friend from Solana!', | ||
message: 'Greetings from Ethereum world.', | ||
}), | ||
} | ||
); | ||
|
||
console.log(tx.txHash); |
Oops, something went wrong.