txSkeleton
Return an array of messages as well as their corresponding position indexes and locks for signing a P2PKH transaction. For more details, please see: https://github.com/nervosnetwork/ckb-system-scripts/wiki/How-to-sign-transaction
TxSkeleton with all input cells' witnessArgs.lock filled with 0.
Locks you want to sign, e.g. you don't need to sign ACP cells.
An array of Group containing: lock of the input cell you need to sign, message for signing, witness index of this message (first index of the input cell with this lock).
Return an array of messages as well as their corresponding position indexes and locks for signing a P2PKH transaction. For more details, please see: https://github.com/nervosnetwork/ckb-system-scripts/wiki/How-to-sign-transaction
TxSkeleton with all input cells' witnessArgs.lock filled with 0.
Locks you want to sign, e.g. you don't need to sign ACP cells.
An array of Group containing: lock of the input cell you need to sign, message for signing, witness index of this message (first index of the input cell with this lock).
deposit a cell to DAO
deposit cell lock address
capacity in shannon
deposit a cell to DAO
deposit cell lock address
capacity in shannon
Generate txSkeleton for writing binary data to CKB, usually for deploying contracts.
This generator only supports SECP256K1_BLAKE160
and SECP256K1_BLAKE160_MULTISIG
currently.
Generate txSkeleton for writing binary data to CKB, usually for deploying contracts.
This generator only supports SECP256K1_BLAKE160
and SECP256K1_BLAKE160_MULTISIG
currently.
Generate txSkeleton for writing binary data to CKB via Type ID, usually for deploying contracts.
Deploying via Type ID makes it possible to upgrade contract, for more information about Type ID, please check: https://xuejie.space/2020_02_03_introduction_to_ckb_script_programming_type_id/
This generator only supports SECP256K1_BLAKE160
and SECP256K1_BLAKE160_MULTISIG
currently.
Generate txSkeleton for writing binary data to CKB via Type ID, usually for deploying contracts.
Deploying via Type ID makes it possible to upgrade contract, for more information about Type ID, please check: https://xuejie.space/2020_02_03_introduction_to_ckb_script_programming_type_id/
This generator only supports SECP256K1_BLAKE160
and SECP256K1_BLAKE160_MULTISIG
currently.
Inject capacity from fromAddress
to target output.
Inject capacity from fromInfo
to target output.
Inject capacity from fromInfo
to target output.
Inject capacity from fromAddress
to target output.
Issue an sUDT cell
Issue an sUDT cell
list DAO cells,
list DAO cells,
lock script args
lock script args
pay fee by secp256k1_blake160 script cells
fee in shannon
pay fee by multisig script cells
fee in shannon
pay fee by multisig script cells
fee in shannon
pay fee by secp256k1_blake160 script cells
fee in shannon
prepare for txSkeleton signingEntries, will update txSkeleton.get("signingEntries")
prepare for txSkeleton signingEntries, will update txSkeleton.get("signingEntries")
prepare for txSkeleton signingEntries, will update txSkeleton.get("signingEntries")
prepare for txSkeleton signingEntries, will update txSkeleton.get("signingEntries")
serialized multisig script
serialized multisig script
A function to transfer input to output, and add input & output to txSkeleton. And it will deal with cell deps and witnesses too. (Add the input required cell deps and witnesses.) It should be noted that the output must be added to the end of txSkeleton.get("outputs").
Setup input cell infos, such as cell deps and witnesses.
Setup input cell infos, such as cell deps and witnesses.
Setup input cell infos, such as cell deps and witnesses.
Setup input cell infos, such as cell deps and witnesses.
A function to transfer input to output, and add input & output to txSkeleton. And it will deal with cell deps and witnesses too. (Add the input required cell deps and witnesses.) It should be noted that the output must be added to the end of txSkeleton.get("outputs").
will not use locktime cells if tipHeader not provided
if not provided, will use first fromInfo
transfer capacity from multisig script cells
fromAddress or fromMultisigScript, if this address new to txSkeleton inputs, must use fromMultisigScript
transfer CKB capacity in shannon.
transfer capacity from multisig script cells
if not provided, will use first fromInfo
transfer capacity from secp256k1_blake160 script cells
transfer capacity from secp256k1_blake160 script cells
will not use locktime cells if tipHeader not provided
transfer capacity from secp256k1_blake160 script cells
transfer capacity from secp256k1_blake160 script cells
Unlock a withdrew DAO cell
deposited DAO cell
withdrew DAO cell
Unlock a withdrew DAO cell
deposited DAO cell
withdrew DAO cell
withdraw an deposited DAO cell
deposited DAO cell
withdraw an deposited DAO cell
deposited DAO cell
infos
includes predefined and customized.
Generated using TypeDoc
@ckb-lumos/common-scripts
Common script implementation for lumos. Includes
secp256k1_blake2b
lock script,secp256k1_blake160_multisig
lock script,dao
type script,sudt
type script now.LocktimePool
script includessecp256k1_blake160_multisig
cells which with locktime in lockargs
(whichargs
total length is 28 bytes, last 8 bytes is asince
format locktime in BigUInt64LE encode) andDAO
step2 cells.common
script allows you totransfer
capacity fromfromInfos
to an address. It will use locktime pool cells first by default.deploy
script providesgenerateDeployWithDataTx
,generateDeployWithTypeIdTx
andgenerateUpgradeTypeIdDataTx
, these generators help in the process of deploying contracts.p2pkh
scripts generates message for signing P2PKH transaction.Usage
common
script support new lock scripts provided by user, andpw-lock
shows how to do it.Following script will show how to use
common
script to transfer capacity to another address.secp256k1_blake160
,secp256k1_blake160_multisig
andlocktime_pool
script are similar tocommon
, andcommon
maybe a better choose.const { common } = require('@ckb-lumos/common-scripts'); const { sealTransaction } = require("@ckb-lumos/helpers") const { Indexer } = require("@ckb-lumos/ckb-indexer") // We can use Indexer module as cell provider const indexer = new Indexer("http://127.0.0.1:8114"); const tipHeader = { compactTarget: '0x20010000', dao: '0x49bfb20771031d556c8480d47f2a290059f0ac7e383b6509006f4a772ed50200', epoch: '0xa0006002b18', hash: '0x432451e23c26f45eaceeedcc261764d6485ea5c9a204ac55ad755bb8dec9a079', nonce: '0x8199548f8a5ac7a0f0caef1620f37b79', number: '0x1aef6', parentHash: '0x63594a64108f19f6aed53d0dca9ab4075aac4379cb80b2097b0deac8fc16fd3b', proposalsHash: '0x0000000000000000000000000000000000000000000000000000000000000000', timestamp: '0x172f6b9a4cf', transactions_root: '0x282dbadcd49f3e229d997875f37f4e4f19cb4f04fcf762e9639145aaa667b6f8', extra_hash: '0x0000000000000000000000000000000000000000000000000000000000000000', version: '0x0' } const fromInfos = [ "ckb1qyqwyxfa75whssgkq9ukkdd30d8c7txct0gq5f9mxs", { R: 0, M: 1, publicKeyHashes: ["0x36c329ed630d6ce750712a477543672adab57f4c"], }, ] let txSkeleton = TransactionSkeleton({ cellProvider: indexer }) // If using secp256k1_blake160_multisig lock script, put MultisigScript to `fromInfos` for generate signing messages. // By default, `common.transfer` will use cells with locktime firstly. `tipHeader` is required when you want to spent cells with locktime. txSkeleton = await common.transfer( txSkeleton, fromInfos, "ckb1qyqrdsefa43s6m882pcj53m4gdnj4k440axqdt9rtd", BigInt(3500 * 10 ** 8), tipHeader, ) // Or you want to use cells without locktime firstly. txSkeleton = await common.transfer( txSkeleton, fromInfos, "ckb1qyqrdsefa43s6m882pcj53m4gdnj4k440axqdt9rtd", BigInt(3500 * 10 ** 8), tipHeader, { useLocktimeCellsFirst: false } ) // When you want to pay fee for transaction, just call `payFee`. txSkeleton = await common.payFee( txSkeleton, fromInfos, BigInt(1*10**8), tipHeader, ) // `prepareSigningEntries` will generate message for signing. // Signing messages will fill in `txSkeleton.signingEntries`. txSkeleton = await common.prepareSigningEntries( txSkeleton ) // Then you can sign messages in order and get contents. // NOTE: lumos not provided tools for generate signatures now. // Call `sealTransaction` to get a transaction. const tx = sealTransaction(txSkeleton, contents) // Then you can send tx to a CKB node via RPC `send_transaction`.
Following script will show how to use
DAO
script.const { dao } = require("@ckb-lumos/common-scripts") let txSkeleton = TransactionSkeleton({ cellProvider: indexer }) // First, deposit capacity to dao. txSkeleton = await dao.deposit( txSkeleton, "ckb1qyqrdsefa43s6m882pcj53m4gdnj4k440axqdt9rtd", // will gather inputs from this address. "ckb1qyqwyxfa75whssgkq9ukkdd30d8c7txct0gq5f9mxs", // will generate a dao cell with lock of this address. BigInt(1000*10**8), ) // Using `listDaoCells` to list all deposited cells. const daoDepositedCells = await dao.listDaoCells( indexer, "ckb1qyqwyxfa75whssgkq9ukkdd30d8c7txct0gq5f9mxs", "deposit", ) // Or using `CellCollector` const daoDepositedCellCollector = new dao.CellCollector( "ckb1qyqwyxfa75whssgkq9ukkdd30d8c7txct0gq5f9mxs", indexer, "deposit", ) for await (const inputCell of daoDepositedCellCollector.collect()) { console.log(inputCell) } // And pick one to withdraw. // `fromInfo` only required for multisig script. txSkeleton = await dao.withdraw( txSkeleton, daoDepositedCells[0], ) // Then if want to unlock dao withdrew cells, just use `common.transfer`.
Following script will show how to use
sUDT
script.const { sudt } = require("@ckb-lumos/common-scripts") let txSkeleton = TransactionSkeleton({ cellProvider: indexer }) // issue an sudt token, will use the second param address to generate sudt token(it's lock hash). txSkeleton = await sudt.issueToken( txSkeleton, "ckb1qyqrdsefa43s6m882pcj53m4gdnj4k440axqdt9rtd", 10000n, ); // and transfer sUDT const sudtToken = "0x1f2615a8dde4e28ca736ff763c2078aff990043f4cbf09eb4b3a58a140a0862d" txSkeleton = await sudt.transfer( txSkeleton, ["ckb1qyqrdsefa43s6m882pcj53m4gdnj4k440axqdt9rtd"], sudtToken, "ckb1qyqwyxfa75whssgkq9ukkdd30d8c7txct0gq5f9mxs", 1000n, "ckb1qyqrdsefa43s6m882pcj53m4gdnj4k440axqdt9rtd", );
Following script will show how to use
deploy
script.const { generateDeployWithDataTx, generateDeployWithTypeIdTx, generateUpgradeTypeIdDataTx, payFee } = require("@ckb-lumos/common-scripts"); const { Indexer } = require("@ckb-lumos/ckb-indexer"); const { initializeConfig, predefined } = require("@ckb-lumos/config-manager"); const { parseAddress } = require("@ckb-lumos/helpers"); initializeConfig(predefined.AGGRON4); const CKB_RPC_URL = "http://localhost:8114"; const CKB_INDEXER_URL = "http://localhost:8116"; const indexer = new Indexer(CKB_INDEXER_URL, CKB_RPC_URL); const address = "ckt1qyqptxys5l9vk39ft0hswscxgseawc77y2wqlr558h"; // Lock script of the deploy account const outputScriptLock = parseAddress(address); // Binary data you want to deploy const scriptBinary = Uint8Array.of(1); let deployOptions = { cellProvider: indexer, scriptBinary: scriptBinary, outputScriptLock: outputScriptLock, } // Ganarate txSkeleton for deploying with data. let txSkeleton = await generateDeployWithDataTx(deployOptions); // Or if you want to delpoy with Type ID so that you can upgarde the contract in the future. let txSkeleton = await generateDeployWithTypeIdTx(deployOptions); // Pay transaction fee. txSkeleton = await payFee(txSkeleton, address, txFee); // Then you can sign and seal the transaction for sending. // To upgrade a contract with Type ID, add its Type ID to deployOptions. const typeId = { codeHash: '0x00000000000000000000000000000000000000000000000000545950455f4944', hashType: 'type', args: '0x7abcd9f949a16b40ff5b50b56e62d2a6a007e544d8491bb56476693b6c45fd27' } const upgradeOptions = { cellProvider: cellProvider, scriptBinary: scriptBinary, outputScriptLock: outputScriptLock, typeId: typeId } // Ganarate txSkeleton for upgrading. let upgradeTxSkeleton = await generateUpgradeTypeIdDataTx(upgradeOptions);
Check omni lock example and pw lock example for how to use
p2pkh
script.