-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransfer-solana.ts
More file actions
40 lines (33 loc) · 1.82 KB
/
Copy pathtransfer-solana.ts
File metadata and controls
40 lines (33 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { config } from 'dotenv';
import { CHAIN_ID, UniversalAccount, UNIVERSAL_ACCOUNT_VERSION } from '@particle-network/universal-account-sdk';
import { getBytes, Wallet } from 'ethers';
config();
(async () => {
const wallet = new Wallet(process.env.PRIVATE_KEY || '');
const universalAccount = new UniversalAccount({
projectId: process.env.PROJECT_ID || '',
projectClientKey: process.env.PROJECT_CLIENT_KEY || "",
projectAppUuid: process.env.PROJECT_APP_UUID || "",
smartAccountOptions: {
name: 'UNIVERSAL',
version: process.env.UNIVERSAL_ACCOUNT_VERSION || UNIVERSAL_ACCOUNT_VERSION,
ownerAddress: wallet.address,
},
});
const smartAccountOptions = await universalAccount.getSmartAccountOptions();
console.log('Your UA EVM Address:', smartAccountOptions.smartAccountAddress);
console.log('Your UA Solana Address:', smartAccountOptions.solanaSmartAccountAddress);
const transaction = await universalAccount.createTransferTransaction({
// 0x0000000000000000000000000000000000000000 means native token
// so here we transfer solana native token to the receiver address
token: { chainId: CHAIN_ID.SOLANA_MAINNET, address: '0x0000000000000000000000000000000000000000' },
// transfer 0.000001 solana native token
amount: '0.000001',
// the receiver address, it must be a solana address
receiver: 'GRHXQJsDHzc9J9trV6aThaH2V924yTra9aFa8MdpUDux',
});
console.log('transfer transaction', transaction);
const sendResult = await universalAccount.sendTransaction(transaction, wallet.signMessageSync(getBytes(transaction.rootHash)));
console.log('sendResult', sendResult);
console.log('explorer url', `https://universalx.app/activity/details?id=${sendResult.transactionId}`);
})();