Created
November 25, 2021 14:33
-
-
Save daoka/d59f90122a99f99392d20ffed1273bfb to your computer and use it in GitHub Desktop.
Revokable mosaic
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
import { Account, AggregateTransaction, Deadline, MosaicDefinitionTransaction, MosaicFlags, MosaicId, MosaicNonce, MosaicSupplyChangeAction, MosaicSupplyChangeTransaction, NetworkType, RepositoryFactoryHttp, TransactionService, UInt64 } from 'symbol-sdk'; | |
async function main() { | |
const node = 'https://sym-test-01.opening-line.jp:3001'; | |
const repoFactory = new RepositoryFactoryHttp(node); | |
const pk = '__INPUT_YOUR_PRIVATE_KEY__'; | |
try { | |
const networkType = await repoFactory.getNetworkType().toPromise(); | |
const generationHash = await repoFactory.getGenerationHash().toPromise(); | |
const epochAdjustment = await repoFactory.getEpochAdjustment().toPromise(); | |
const account = Account.createFromPrivateKey(pk, networkType); | |
console.log(account.address.plain()); | |
const div = 0; | |
const nonce = MosaicNonce.createRandom(); | |
const mosaicDefinitionTx = MosaicDefinitionTransaction.create( | |
Deadline.create(epochAdjustment), | |
nonce, | |
MosaicId.createFromNonce(nonce, account.address), | |
MosaicFlags.create(true, true, false, true), | |
div, | |
UInt64.fromUint(0), | |
networkType | |
); | |
const supply = 10000; | |
const mosaicSupplyTx = MosaicSupplyChangeTransaction.create( | |
Deadline.create(epochAdjustment), | |
mosaicDefinitionTx.mosaicId, | |
MosaicSupplyChangeAction.Increase, | |
UInt64.fromUint(supply * Math.pow(10, div)), | |
networkType | |
); | |
const aggregateTx = AggregateTransaction.createComplete( | |
Deadline.create(epochAdjustment), | |
[ | |
mosaicDefinitionTx.toAggregate(account.publicAccount), | |
mosaicSupplyTx.toAggregate(account.publicAccount), | |
], | |
networkType, | |
[] | |
).setMaxFeeForAggregate(100, 1); | |
const signedTx = account.sign(aggregateTx, generationHash); | |
const transactionRepo = repoFactory.createTransactionRepository(); | |
const receiptRepo = repoFactory.createReceiptRepository(); | |
const listener = repoFactory.createListener(); | |
const transactionService = new TransactionService(transactionRepo, receiptRepo); | |
listener.open().then(() => { | |
transactionService.announce(signedTx, listener).subscribe((x) => { | |
console.log(x); | |
listener.close(); | |
}, (err) => { | |
console.error(err); | |
listener.close(); | |
}) | |
}) | |
} catch(err) { | |
throw(err); | |
} | |
} | |
main().then(() => {}).catch((err) => { console.error(err) }); |
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
import { Account, Address, AggregateTransaction, Deadline, Mosaic, MosaicDefinitionTransaction, MosaicFlags, MosaicId, MosaicNonce, MosaicSupplyChangeAction, MosaicSupplyChangeTransaction, MosaicSupplyRevocationTransaction, NetworkType, RepositoryFactoryHttp, TransactionService, UInt64 } from 'symbol-sdk'; | |
async function main() { | |
const node = 'https://sym-test-01.opening-line.jp:3001'; | |
const repoFactory = new RepositoryFactoryHttp(node); | |
const pk = '__INPUT_YOUR_PRIVATE_KEY__'; | |
try { | |
const networkType = await repoFactory.getNetworkType().toPromise(); | |
const generationHash = await repoFactory.getGenerationHash().toPromise(); | |
const epochAdjustment = await repoFactory.getEpochAdjustment().toPromise(); | |
const account = Account.createFromPrivateKey(pk, networkType); | |
const mosaicId = new MosaicId('__INPUT_MOSAIC_ID__'); | |
const tx = MosaicSupplyRevocationTransaction.create( | |
Deadline.create(epochAdjustment), | |
Address.createFromRawAddress('__INPUT_TARGET_ADDRESS__'), | |
new Mosaic(mosaicId, UInt64.fromUint(10)), | |
networkType, | |
).setMaxFee(100); | |
const signedTx = account.sign(tx, generationHash); | |
const transactionRepo = repoFactory.createTransactionRepository(); | |
const receiptRepo = repoFactory.createReceiptRepository(); | |
const listener = repoFactory.createListener(); | |
const transactionService = new TransactionService(transactionRepo, receiptRepo); | |
listener.open().then(() => { | |
transactionService.announce(signedTx, listener).subscribe((x) => { | |
console.log(x); | |
listener.close(); | |
}, (err) => { | |
console.error(err); | |
listener.close(); | |
}) | |
}) | |
} catch(err) { | |
throw(err); | |
} | |
} | |
main().then(() => {}).catch((err) => { console.error(err) }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment