-
Notifications
You must be signed in to change notification settings - Fork 19
/
backend-lyx-transaction.ts
40 lines (34 loc) · 1.46 KB
/
backend-lyx-transaction.ts
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 { ethers } from 'ethers';
import UniversalProfile from '@lukso/lsp-smart-contracts/artifacts/UniversalProfile.json';
// Connect to the testnet
const RPC_ENDPOINT = 'https://4201.rpc.thirdweb.com';
const provider = new ethers.JsonRpcProvider(RPC_ENDPOINT);
// Get the controller key of the Universal Profile
const controller = '0x...'; // Replace with the controller address
// 💡 Request LYXt from the faucet:
// 🚰 https://faucet.testnet.lukso.network/
// Instantiate Universal Profile
const userProfileAddress = '0x...'; // Replace with the user's profile address
const myUniversalProfile = new ethers.Contract(
userProfileAddress,
UniversalProfile.abi,
provider,
);
(async () => {
try {
// Call the execute function of the profile to send the LYX transaction
// Will forward to the LSP6 Key Manager to check permissions of the controller
const transaction = await myUniversalProfile.execute(
0, // operation of type CALL
'0x...', // recipient address including profiles and vaults
ethers.parseEther('0.5'), // amount in LYX, converting to wei
'0x...', // contract calldata, empty for regular transfer
{ gasLimit: 300000, from: controller }, // gas limit of the transaction and sender address
);
const txReceipt = await transaction.wait();
console.log('Transaction hash:', txReceipt.transactionHash);
console.log('Transaction successful.');
} catch (error) {
console.error('Error:', error);
}
})();