Build & Model A FAT-0 Transaction
Kind: global class
Access: public
- TransactionBuilder0
- new TransactionBuilder(Transaction)
- .input(fs, amount) ⇒
TransactionBuilder
- .coinbaseInput(amount) ⇒
TransactionBuilder
- .output(fa, amount) ⇒
TransactionBuilder
- .burnOutput(amount) ⇒
TransactionBuilder
- .sk1(sk1) ⇒
TransactionBuilder
- .id1(id1) ⇒
TransactionBuilder
- .id1Signature(id1, signature) ⇒
TransactionBuilder
- .metadata(metadata) ⇒
TransactionBuilder
- .pkSignature(publicKey, signature) ⇒
TransactionBuilder
- .build() ⇒
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();
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 |
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 |
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 |
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 |
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 |
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 |
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 |
Set arbitrary metadata for the transaction
Kind: instance method of TransactionBuilder0
Param | Type | Description |
---|---|---|
metadata | * |
The metadata. Must be JSON stringifyable |
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 |
Build the transaction
Kind: instance method of TransactionBuilder0