Skip to content

Latest commit

 

History

History
187 lines (132 loc) · 8.58 KB

TransactionBuilder0.md

File metadata and controls

187 lines (132 loc) · 8.58 KB

TransactionBuilder0

Build & Model A FAT-0 Transaction

Kind: global class
Access: public

new TransactionBuilder(Transaction)

Param Type Description
Transaction Transaction | string or tokenChainId - Unsigned transaction or 64 character Factom Chain ID of the token to build the transaction for

Example

const TransactionBuilder = require('fat-js').FAT0.TransactionBuilder

const tokenChainId = '013de826902b7d075f00101649ca4fa7b49b5157cba736b2ca90f67e2ad6e8ec';

let tx = new TransactionBuilder(tokenChainId)
.input("Fs1q7FHcW4Ti9tngdGAbA3CxMjhyXtNyB1BSdc8uR46jVUVCWtbJ", 150)
.output("FA3aECpw3gEZ7CMQvRNxEtKBGKAos3922oqYLcHQ9NqXHudC6YBM", 150)
.build();

//coinbase transaction
tx = new TransactionBuilder(tokenChainId)
.coinbaseInput(10)
.output("FA3aECpw3gEZ7CMQvRNxEtKBGKAos3922oqYLcHQ9NqXHudC6YBM", 10)
.sk1("sk13Rp3LVmVvWqo8mff82aDJN2yNCzjUs2Zuq3MNQSA5oC5ZwFAuu")
.build();

//burn transaction
tx = new TransactionBuilder(tokenChainId)
.input("Fs1PkAEbmo1XNangSnxmKqi1PN5sVDbQ6zsnXCsMUejT66WaDgkm", 150)
.burnOutput(150)
.build();

//transaction metadata
tx = new TransactionBuilder(tokenChainId)
.input("Fs1PkAEbmo1XNangSnxmKqi1PN5sVDbQ6zsnXCsMUejT66WaDgkm", 150)
.output("FA3aECpw3gEZ7CMQvRNxEtKBGKAos3922oqYLcHQ9NqXHudC6YBM", 150)
.metadata({type: 'fat-js test run', timestamp: new Date().getTime()})
.build();

//You can also use external signatures (from hardware devices, etc):

let keyPair = nacl.keyPair.fromSeed(fctAddrUtils.addressToKey("Fs1q7FHcW4Ti9tngdGAbA3CxMjhyXtNyB1BSdc8uR46jVUVCWtbJ"));
let pubaddr = fctAddrUtils.keyToPublicFctAddress(keyPair.publicKey);

let unsignedTx = new TransactionBuilder(testTokenChainId)
.input(pubaddr, 150)
.output("FA3umTvVhkcysBewF1sGAMeAeKDdG7kTQBbtf5nwuFUGwrNa5kAr", 150)
.build();

let extsig = nacl.detached(fctUtil.sha512(unsignedTx.getMarshalDataSig(0)), keyPair.secretKey);

let signedTx = new TransactionBuilder(unsignedTx)
.pkSignature(keyPair.publicKey, extsig)
.build();

transactionBuilder0.input(fs, amount) ⇒ TransactionBuilder

Set up a Factoid address input for the transaction

Kind: instance method of TransactionBuilder0

Param Type Description
fs string The private Factoid address to use as the input of the transaction OR raw public key if supplying external signatures
amount number | string | BigNumber The integer amount of token units to send. Native JS Numbers (e.x. 123), strings (e.x. "123"), and BigNumbers(e.x. new BigNumber("9999999999999999") are allowed as long as they represent integers

transactionBuilder0.coinbaseInput(amount) ⇒ TransactionBuilder

Set up a coinbase input for the transaction, which mints tokens

Kind: instance method of TransactionBuilder0

Param Type Description
amount number | string | BigNumber The integer amount of token units to send. Native JS Numbers (e.x. 123), strings (e.x. '123'), and BigNumbers(e.x. new BigNumber("9999999999999999") are allowed as long as they represent integers

transactionBuilder0.output(fa, amount) ⇒ TransactionBuilder

Set up a Factoid address output for the transaction

Kind: instance method of TransactionBuilder0

Param Type Description
fa string The public Factoid address destination of the output
amount number | string | BigNumber The integer amount of token units to receive at the destination address. Native JS Numbers (e.x. 123), strings (e.x. "123"), and BigNumbers(e.x. new BigNumber("9999999999999999") are allowed as long as they represent integers

transactionBuilder0.burnOutput(amount) ⇒ TransactionBuilder

Set up a burn output for the transaction, which will destroy tokens

Kind: instance method of TransactionBuilder0

Param Type Description
amount number | string | BigNumber The integer amount of token units to receive at the destination address. Native JS Numbers (e.x. 123), strings (e.x. "123"), and BigNumbers(e.x. new BigNumber("9999999999999999") are allowed as long as they represent integers

transactionBuilder0.sk1(sk1) ⇒ TransactionBuilder

Set the SK1 private key of the token's issuing identity. Required for coinbase transactions

Kind: instance method of TransactionBuilder0

Param Type Description
sk1 string The SK1 private key string of the issuing identity

transactionBuilder0.id1(id1) ⇒ TransactionBuilder

Set up the identity public key of the issuing identity in prep for an externally signed coinbase transaction

Kind: instance method of TransactionBuilder0

Param Type Description
id1 string The ID1 public key string of the issuing identity, external signature will be required in second pass

transactionBuilder0.id1Signature(id1, signature) ⇒ TransactionBuilder

Set up the identity signature of the issuing identity in prep for an externally signed coinbase transaction

Kind: instance method of TransactionBuilder0

Param Type Description
id1 string The ID1 public key string of the issuing identity, external signature expected.
signature Buffer signature - Optional signature provided on second pass

transactionBuilder0.metadata(metadata) ⇒ TransactionBuilder

Set arbitrary metadata for the transaction

Kind: instance method of TransactionBuilder0

Param Type Description
metadata * The metadata. Must be JSON stringifyable

transactionBuilder0.pkSignature(publicKey, signature) ⇒ TransactionBuilder

Add a public key and signature to the transaction. This is used only in the case of externally signed transactions (useful for hardware wallets). Public Key's /signatures need to be added in the same order as their corresponding inputs.

Kind: instance method of TransactionBuilder0
Returns: TransactionBuilder - - TransactionBuilder instance.

Param Type Description
publicKey string | Array | Buffer FCT public key as hex string, uint8array, or buffer
signature Buffer Signature

transactionBuilder0.build() ⇒ Transaction

Build the transaction

Kind: instance method of TransactionBuilder0