Last active
May 5, 2021 17:02
-
-
Save cgcardona/3be73231f7a841cfdc07266b8b6cb427 to your computer and use it in GitHub Desktop.
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 { | |
Avalanche, | |
BinTools, | |
BN, | |
Buffer | |
} from "../../src"; | |
import { | |
AVMAPI, | |
KeyChain, | |
UTXOSet, | |
UnsignedTx, | |
Tx, | |
InitialStates, | |
SECPMintOutput, | |
SECPTransferOutput | |
} from "../../src/apis/avm" | |
const ip: string = "localhost" | |
const port: number = 9650 | |
const protocol: string = "http" | |
const networkID: number = 12345 | |
const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) | |
const xchain: AVMAPI = avalanche.XChain() | |
const bintools: BinTools = BinTools.getInstance() | |
const xKeychain: KeyChain = xchain.keyChain() | |
const privKey: string = "PrivateKey-ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN" | |
xKeychain.importKey(privKey) | |
const xAddresses: Buffer[] = xchain.keyChain().getAddresses() | |
const xAddressStrings: string[] = xchain.keyChain().getAddressStrings() | |
const outputs: SECPMintOutput[] = [] | |
const threshold: number = 1 | |
const locktime: BN = new BN(0) | |
const memo: Buffer = Buffer.from("Creating token: SNEK - The Danger Noodle") | |
const name: string = "The Danger Noodle" | |
const symbol: string = "SNEK" | |
// 1 AVAX is denomination 9, so the smallest unit of AVAX is nanoAVAX (nAVAX) at 10^-9 AVAX | |
const denomination: number = 0 | |
const main = async (): Promise<any> => { | |
const avmUTXOResponse: any = await xchain.getUTXOs(xAddressStrings) | |
const utxoSet: UTXOSet = avmUTXOResponse.utxos | |
const amount: BN = new BN(507) | |
const vcapSecpOutput = new SECPTransferOutput(amount, xAddresses, locktime, threshold) | |
const initialStates: InitialStates = new InitialStates() | |
initialStates.addOutput(vcapSecpOutput) | |
const secpMintOutput: SECPMintOutput = new SECPMintOutput(xAddresses, locktime, threshold) | |
outputs.push(secpMintOutput) | |
const unsignedTx: UnsignedTx = await xchain.buildCreateAssetTx( | |
utxoSet, | |
xAddressStrings, | |
xAddressStrings, | |
initialStates, | |
name, | |
symbol, | |
denomination, | |
outputs, | |
memo | |
) | |
const tx: Tx = unsignedTx.sign(xKeychain) | |
console.log(bintools.cb58Encode(tx.toBuffer())) | |
const txid: string = await xchain.issueTx(tx) | |
console.log(`Success! TXID: ${txid}`) | |
} | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment