Skip to content

Instantly share code, notes, and snippets.

@dungvn3000
Created October 14, 2025 15:20
Show Gist options
  • Select an option

  • Save dungvn3000/8e4cb665ca566d802822e331c2fbdf79 to your computer and use it in GitHub Desktop.

Select an option

Save dungvn3000/8e4cb665ca566d802822e331c2fbdf79 to your computer and use it in GitHub Desktop.
Fleet-sdk Pin Lock Contract
import { OutputBuilder, TransactionBuilder } from '@fleet-sdk/core';
import { compile } from '@fleet-sdk/compiler';
import { SByte, SColl } from '@fleet-sdk/serializer';
import { blake2b256 } from '@fleet-sdk/crypto';
(async () => {
if (await ergoConnector.nautilus.connect()) {
const pinLockContract = compile(
'sigmaProp(SELF.R4[Coll[Byte]].get == blake2b256(OUTPUTS(0).R4[Coll[Byte]].get))'
);
console.log(pinLockContract.toHex());
const pinNumber = '1293';
const output1 = new OutputBuilder(
'10000000',
pinLockContract
).setAdditionalRegisters({
R4: SColl(SByte, blake2b256(pinNumber)),
});
const height = await ergo.get_current_height();
const utxo = await ergo.get_utxos();
console.log(utxo);
const unsignedTx = new TransactionBuilder(height)
.from(await ergo.get_utxos()) // add inputs from dApp Connector
.to(output1)
.sendChangeTo(await ergo.get_change_address()) // Set the change address to the user's default change address
.payMinFee() // set minimal transaction fee
.build() // build the transaction
.toEIP12Object(); // converts the ErgoUnsignedTransaction instance to an dApp Connector compatible plain object
const signedTx = await ergo.sign_tx(unsignedTx);
// send the signed transaction to the mempool
const txId = await ergo.submit_tx(signedTx);
// prints the Transaction ID of the submitted transaction on the console
console.log(txId);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment