Skip to content

Commit cdf5cd3

Browse files
authored
Create PiCoinStable.js
1 parent 468e1d1 commit cdf5cd3

File tree

1 file changed

+61
-0
lines changed
  • blockchain_integration/pi_network/SpacePi/blockchain/contracts/mainnet

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Import the Stellar SDK
2+
const StellarSdk = require('stellar-sdk');
3+
4+
// Connect to the Stellar mainnet
5+
const server = new StellarSdk.Server('https://horizon.stellar.org');
6+
7+
// Replace with your secret key
8+
const issuerSecret = 'YOUR_ISSUER_SECRET_KEY'; // Replace with your actual secret key
9+
const issuerKeypair = StellarSdk.Keypair.fromSecret(issuerSecret);
10+
const assetName = 'PI'; // Token name
11+
const assetAmount = '100000000000'; // Total supply (100 billion tokens)
12+
13+
// Pegged value in USD
14+
const peggedValue = 314159; // Pegged value in USD
15+
16+
async function createToken() {
17+
try {
18+
// Create a new asset
19+
const asset = new StellarSdk.Asset(assetName, issuerKeypair.publicKey());
20+
21+
// Load the issuer account
22+
const account = await server.loadAccount(issuerKeypair.publicKey());
23+
24+
// Create a transaction to issue the asset
25+
const transaction = new StellarSdk.TransactionBuilder(account, {
26+
fee: await server.fetchBaseFee(),
27+
networkPassphrase: StellarSdk.Networks.PUBLIC, // Use PUBLIC for mainnet
28+
})
29+
.addOperation(StellarSdk.Operation.changeTrust({
30+
asset: asset,
31+
limit: assetAmount,
32+
}))
33+
.setTimeout(30)
34+
.build();
35+
36+
// Sign the transaction
37+
transaction.sign(issuerKeypair);
38+
39+
// Submit the transaction
40+
const result = await server.submitTransaction(transaction);
41+
console.log('Token created successfully:', result);
42+
console.log(`The token ${assetName} is pegged to a value of $${peggedValue}.`);
43+
44+
// Check the issuer's balance
45+
await checkIssuerBalance();
46+
} catch (error) {
47+
console.error('Error creating token:', error);
48+
}
49+
}
50+
51+
async function checkIssuerBalance() {
52+
try {
53+
const account = await server.loadAccount(issuerKeypair.publicKey());
54+
console.log(`Issuer balance: ${JSON.stringify(account.balances, null, 2)}`);
55+
} catch (error) {
56+
console.error('Error fetching issuer balance:', error);
57+
}
58+
}
59+
60+
// Execute the function to create the token
61+
createToken();

0 commit comments

Comments
 (0)