diff --git a/example/aggregator/package.json b/example/aggregator/package.json index 5dbd257..dbfdf9e 100644 --- a/example/aggregator/package.json +++ b/example/aggregator/package.json @@ -8,10 +8,10 @@ "build": "tsc" }, "dependencies": { - "@nervina-labs/cota-sdk": "0.4.6", + "@nervina-labs/cota-sdk": "0.4.7", "@types/node": "17.0.21", "ts-node": "10.7.0", "tslib": "2.4.0", "typescript": "4.6.4" } -} +} \ No newline at end of file diff --git a/example/aggregator/yarn.lock b/example/aggregator/yarn.lock index b97f413..c22b6ec 100644 --- a/example/aggregator/yarn.lock +++ b/example/aggregator/yarn.lock @@ -14,10 +14,10 @@ dependencies: "@cspotcode/source-map-consumer" "0.8.0" -"@nervina-labs/cota-sdk@0.4.6": - version "0.4.6" - resolved "https://registry.yarnpkg.com/@nervina-labs/cota-sdk/-/cota-sdk-0.4.6.tgz#605ec070d7ce4a641c5698b6d91704e1ad811065" - integrity sha512-41y9wjc1wcKPzYaikQ0Z/Xoesy8ppQntdPFdfjq8EvocoG7q9EHGIACDZ+XdZjpblNVXTsXdOMJs5bI/rBflRQ== +"@nervina-labs/cota-sdk@0.4.7": + version "0.4.7" + resolved "https://registry.yarnpkg.com/@nervina-labs/cota-sdk/-/cota-sdk-0.4.7.tgz#889a8ec8e9f5e00749010967cf458e6f54e10c5a" + integrity sha512-qTCf/pb+WvSrtlryDJGoVBQU4WjihQ8ryIUHpbg0aelndaWSSiQpNL86yY7bp5WbkAs6yejxOnxO/Jo+gqSO0Q== dependencies: "@nervosnetwork/ckb-sdk-core" "^0.102.3" "@nervosnetwork/ckb-sdk-utils" "^0.102.3" diff --git a/example/claim-update.ts b/example/claim-update.ts index 952e9c0..7842130 100644 --- a/example/claim-update.ts +++ b/example/claim-update.ts @@ -3,18 +3,28 @@ import { Collector } from '../src/collector' import { Aggregator } from '../src/aggregator' import { generateClaimUpdateCotaTx } from '../src/service/cota' import { CotaNft, Service, FEE } from '../src' -import CKB from '@nervosnetwork/ckb-sdk-core' const TEST_ADDRESS = 'ckt1qyq0scej4vn0uka238m63azcel7cmcme7f2sxj5ska' -const RECEIVER_PRIVATE_KEY = '0xcf56c11ce3fbec627e5118acd215838d1f9c5048039792d42143f933cde76311' -const RECEIVER_ADDRESS = 'ckt1qyqdcu8n8h5xlhecrd8ut0cf9wer6qnhfqqsnz3lw9' - -const secp256k1CellDep = async (ckb: CKB): Promise => { - const secp256k1Dep = (await ckb.loadDeps()).secp256k1Dep - return { outPoint: secp256k1Dep.outPoint, depType: 'depGroup' } +const RECEIVER_PRIVATE_KEY = '0xf0d72b5e3a27e603efb304aa16608ba3e480cb1c6790bced80fb82c53a822cee' +const RECEIVER_ADDRESS = 'ckt1qyqy6xew5q449zg5du7wdjhgrxschjkg3n2q8h5ycc' + +const secp256k1CellDep = (isMainnet: boolean): CKBComponents.CellDep => { + if (isMainnet) { + return { outPoint: { + txHash: "0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c", + index: "0x0", + }, depType: 'depGroup' } + } + return { outPoint: { + txHash: "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37", + index: "0x0", + }, depType: 'depGroup' } } const run = async () => { + // True for mainnet and false for testnet + const isMainnet = false + const service: Service = { collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }), aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }), @@ -31,14 +41,9 @@ const run = async () => { characteristic: '0xa5a5a50505050505050505050505050505050505', }, ] - //Testnet - let rawTx = await generateClaimUpdateCotaTx(service, claimLock, withdrawLock, nfts) - - // Mainnet - // let rawTx = await generateClaimUpdateCotaTx(service, claimLock, withdrawLock, nfts, FEE, true) + let rawTx = await generateClaimUpdateCotaTx(service, claimLock, withdrawLock, nfts, FEE, isMainnet) - const secp256k1Dep = await secp256k1CellDep(ckb) - rawTx.cellDeps.push(secp256k1Dep) + rawTx.cellDeps.push(secp256k1CellDep(isMainnet)) const signedTx = ckb.signTransaction(RECEIVER_PRIVATE_KEY)(rawTx) console.log(JSON.stringify(signedTx)) diff --git a/example/claim.ts b/example/claim.ts index f79507f..3e6758a 100644 --- a/example/claim.ts +++ b/example/claim.ts @@ -3,18 +3,28 @@ import { Collector } from '../src/collector' import { Aggregator } from '../src/aggregator' import { generateClaimCotaTx } from '../src/service/cota' import { Claim, Service, FEE } from '../src' -import CKB from '@nervosnetwork/ckb-sdk-core' const TEST_ADDRESS = 'ckt1qyq0scej4vn0uka238m63azcel7cmcme7f2sxj5ska' -const RECEIVER_PRIVATE_KEY = '0xcf56c11ce3fbec627e5118acd215838d1f9c5048039792d42143f933cde76311' -const RECEIVER_ADDRESS = 'ckt1qyqdcu8n8h5xlhecrd8ut0cf9wer6qnhfqqsnz3lw9' - -const secp256k1CellDep = async (ckb: CKB): Promise => { - const secp256k1Dep = (await ckb.loadDeps()).secp256k1Dep - return { outPoint: secp256k1Dep.outPoint, depType: 'depGroup' } +const RECEIVER_PRIVATE_KEY = '0xf0d72b5e3a27e603efb304aa16608ba3e480cb1c6790bced80fb82c53a822cee' +const RECEIVER_ADDRESS = 'ckt1qyqy6xew5q449zg5du7wdjhgrxschjkg3n2q8h5ycc' + +const secp256k1CellDep = (isMainnet: boolean): CKBComponents.CellDep => { + if (isMainnet) { + return { outPoint: { + txHash: "0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c", + index: "0x0", + }, depType: 'depGroup' } + } + return { outPoint: { + txHash: "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37", + index: "0x0", + }, depType: 'depGroup' } } const run = async () => { + // True for mainnet and false for testnet + const isMainnet = false + const service: Service = { collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }), aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }), @@ -26,17 +36,11 @@ const run = async () => { const claims: Claim[] = [ { cotaId: '0xc27328c95e27723d42770261d05355977aa5c89a', - tokenIndex: '0x00000018', + tokenIndex: '0x0000000b', }, ] - // Testnet - let rawTx = await generateClaimCotaTx(service, claimLock, withdrawLock, claims) - - // Mainnet - // let rawTx = await generateClaimCotaTx(service, claimLock, withdrawLock, claims, FEE, true) - - const secp256k1Dep = await secp256k1CellDep(ckb) - rawTx.cellDeps.push(secp256k1Dep) + let rawTx = await generateClaimCotaTx(service, claimLock, withdrawLock, claims, FEE, isMainnet) + rawTx.cellDeps.push(secp256k1CellDep(isMainnet)) const signedTx = ckb.signTransaction(RECEIVER_PRIVATE_KEY)(rawTx) console.log(JSON.stringify(signedTx)) diff --git a/example/define-flashsigner.ts b/example/define-flashsigner.ts index 82506bd..eb4f742 100644 --- a/example/define-flashsigner.ts +++ b/example/define-flashsigner.ts @@ -8,6 +8,9 @@ import { toSnakeCase } from '../src/utils' const TEST_ADDRESS = 'ckt1qpth5hjexr3wehtzqpm97dzzucgemjv7sl05wnez7y72hqvuszeyyqvz2vhrf3xz0jr8dcmxlv059kmpx4tt5vcluapd4' const run = async () => { + // True for mainnet and false for testnet + const isMainnet = false + const service: Service = { collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }), aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }), @@ -21,10 +24,7 @@ const run = async () => { image: "https://i.loli.net/2021/04/29/qyJNSE4iHAas7GL.png", } - let { rawTx, cotaId } = await generateDefineCotaTx(service, defineLock, 0, '0x00', cotaInfo) - - // Mainnet - // let { rawTx, cotaId } = await generateDefineCotaTx(service, defineLock, 0, '0x00', cotaInfo, FEE, true) + let { rawTx, cotaId } = await generateDefineCotaTx(service, defineLock, 0, '0x00', cotaInfo, FEE, isMainnet) console.log(`cotaId: ${cotaId}`) const flashsingerDep: CKBComponents.CellDep = { diff --git a/example/define.ts b/example/define.ts index 24f613b..8e39134 100644 --- a/example/define.ts +++ b/example/define.ts @@ -21,6 +21,9 @@ const secp256k1CellDep = (isMainnet: boolean): CKBComponents.CellDep => { } const run = async () => { + // True for mainnet and false for testnet + const isMainnet = false + const service: Service = { collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }), aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }), @@ -34,14 +37,10 @@ const run = async () => { image: "https://i.loli.net/2021/04/29/qyJNSE4iHAas7GL.png", } - // Testnet - let { rawTx, cotaId } = await generateDefineCotaTx(service, defineLock, 0, '0x00', cotaInfo) - - // Mainnet - // let { rawTx, cotaId } = await generateDefineCotaTx(service, defineLock, 0, '0x00', cotaInfo, FEE, true) + let { rawTx, cotaId } = await generateDefineCotaTx(service, defineLock, 0, '0x00', cotaInfo, FEE, isMainnet) console.log(`cotaId: ${cotaId}`) - rawTx.cellDeps.push(secp256k1CellDep(false)) + rawTx.cellDeps.push(secp256k1CellDep(isMainnet)) const signedTx = ckb.signTransaction(TEST_PRIVATE_KEY)(rawTx) console.log(JSON.stringify(signedTx)) diff --git a/example/issuer.ts b/example/issuer.ts index aa8eb44..4210c9a 100644 --- a/example/issuer.ts +++ b/example/issuer.ts @@ -3,17 +3,27 @@ import { Collector } from '../src/collector' import { Aggregator } from '../src/aggregator' import { generateIssuerInfoTx } from '../src/service/cota' import { IssuerInfo, Service, FEE } from '../src' -import CKB from '@nervosnetwork/ckb-sdk-core' const TEST_PRIVATE_KEY = '0xc5bd09c9b954559c70a77d68bde95369e2ce910556ddc20f739080cde3b62ef2' const TEST_ADDRESS = 'ckt1qyq0scej4vn0uka238m63azcel7cmcme7f2sxj5ska' -const secp256k1CellDep = async (ckb: CKB): Promise => { - const secp256k1Dep = (await ckb.loadDeps()).secp256k1Dep - return { outPoint: secp256k1Dep.outPoint, depType: 'depGroup' } +const secp256k1CellDep = (isMainnet: boolean): CKBComponents.CellDep => { + if (isMainnet) { + return { outPoint: { + txHash: "0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c", + index: "0x0", + }, depType: 'depGroup' } + } + return { outPoint: { + txHash: "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37", + index: "0x0", + }, depType: 'depGroup' } } const run = async () => { + // True for mainnet and false for testnet + const isMainnet = false + const service: Service = { collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }), aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }), @@ -27,14 +37,8 @@ const run = async () => { avatar: "https://i.loli.net/2021/04/29/IigbpOWP8fw9qDn.png", } - // Testnet - let rawTx = await generateIssuerInfoTx(service, cotaLock, issuer) - - // Mainnet - // let rawTx = await generateIssuerInfoTx(service, cotaLock, issuer, FEE, true) - - const secp256k1Dep = await secp256k1CellDep(ckb) - rawTx.cellDeps.push(secp256k1Dep) + let rawTx = await generateIssuerInfoTx(service, cotaLock, issuer, FEE, isMainnet) + rawTx.cellDeps.push(secp256k1CellDep(isMainnet)) const signedTx = ckb.signTransaction(TEST_PRIVATE_KEY)(rawTx) console.log(JSON.stringify(signedTx)) diff --git a/example/mainnet/define.js b/example/mainnet/define.js new file mode 100644 index 0000000..100a4a3 --- /dev/null +++ b/example/mainnet/define.js @@ -0,0 +1,55 @@ +const { addressToScript } = require('@nervosnetwork/ckb-sdk-utils') +const { Collector, Aggregator, generateDefineCotaTx, FEE } = require('@nervina-labs/cota-sdk') + +// AliceMainnet +const TEST_PRIVATE_KEY = '0x-example' +const TEST_ADDRESS = 'ckb1qyqxx0xdw7g67eu35nuj0f237eg8skpdctuqwx39xm' + +const secp256k1CellDep = isMainnet => { + if (isMainnet) { + return { + outPoint: { + txHash: '0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c', + index: '0x0', + }, + depType: 'depGroup', + } + } + return { + outPoint: { + txHash: '0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37', + index: '0x0', + }, + depType: 'depGroup', + } +} + +const run = async () => { + // True for mainnet and false for testnet + const isMainnet = true + + const service = { + collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }), + aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }), + } + const ckb = service.collector.getCkb() + const defineLock = addressToScript(TEST_ADDRESS) + + const cotaInfo = { + name: 'CoTA NFT by SDK', + description: 'The CoTA NFT from CoTA SDK.\n\n-- Which can make the cost reduction.', + image: 'https://oss.jinse.cc/production/03249d00-6b65-4aac-9147-a6d5d9127542.png', + } + + let { rawTx, cotaId } = await generateDefineCotaTx(service, defineLock, 0, '0x00', cotaInfo, FEE, isMainnet) + + console.log(`cotaId: ${cotaId}`) + rawTx.cellDeps.push(secp256k1CellDep(isMainnet)) + + const signedTx = ckb.signTransaction(TEST_PRIVATE_KEY)(rawTx) + console.log(JSON.stringify(signedTx)) + let txHash = await ckb.rpc.sendTransaction(signedTx, 'passthrough') + console.info(`Define cota nft tx has been sent with tx hash ${txHash}`) +} + +run() diff --git a/example/mainnet/mint.js b/example/mainnet/mint.js new file mode 100644 index 0000000..dbd019c --- /dev/null +++ b/example/mainnet/mint.js @@ -0,0 +1,67 @@ +const { addressToScript, serializeScript } = require('@nervosnetwork/ckb-sdk-utils') +const { Collector, Aggregator, generateMintCotaTx, FEE } = require('@nervina-labs/cota-sdk') + +// AliceMainnet +const TEST_PRIVATE_KEY = '0x-example' +const TEST_ADDRESS = 'ckb1qyqxx0xdw7g67eu35nuj0f237eg8skpdctuqwx39xm' +const RECEIVER_ADDRESS = 'ckb1qyqxx0xdw7g67eu35nuj0f237eg8skpdctuqwx39xm' + +const secp256k1CellDep = isMainnet => { + if (isMainnet) { + return { + outPoint: { + txHash: '0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c', + index: '0x0', + }, + depType: 'depGroup', + } + } + return { + outPoint: { + txHash: '0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37', + index: '0x0', + }, + depType: 'depGroup', + } +} + +const run = async () => { + // True for mainnet and false for testnet + const isMainnet = true + + const service = { + collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }), + aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }), + } + const ckb = service.collector.getCkb() + const mintLock = addressToScript(TEST_ADDRESS) + + // If any tokenIndex of MintCotaInfo is not set, the tokenIndex will be set automatically with issued count. + const mintCotaInfo = { + cotaId: '0xae223946058e5b148045d11483df60b36dc28a30', + withdrawals: [ + { + // tokenIndex: '0x00000000', + state: '0x00', + characteristic: '0x0505050505050505050505050505050505050505', + toLockScript: serializeScript(addressToScript(RECEIVER_ADDRESS)), + }, + { + // tokenIndex: '0x00000001', + state: '0x00', + characteristic: '0x0505050505050505050505050505050505050505', + toLockScript: serializeScript(addressToScript(RECEIVER_ADDRESS)), + }, + ], + } + + let rawTx = await generateMintCotaTx(service, mintLock, mintCotaInfo, FEE, isMainnet) + rawTx.cellDeps.push(secp256k1CellDep(isMainnet)) + + const signedTx = ckb.signTransaction(TEST_PRIVATE_KEY)(rawTx) + console.log(JSON.stringify(signedTx)) + let txHash = await ckb.rpc.sendTransaction(signedTx, 'passthrough') + console.info(`Mint cota nft tx has been sent with tx hash ${txHash}`) +} + +run() diff --git a/example/mainnet/package.json b/example/mainnet/package.json new file mode 100644 index 0000000..c4d6e9a --- /dev/null +++ b/example/mainnet/package.json @@ -0,0 +1,9 @@ +{ + "name": "mainnet-example", + "version": "1.0.0", + "description": "The examples for mainnet", + "license": "MIT", + "dependencies": { + "@nervina-labs/cota-sdk": "0.4.7" + } +} \ No newline at end of file diff --git a/example/mainnet/registry.js b/example/mainnet/registry.js new file mode 100644 index 0000000..4cd1ba3 --- /dev/null +++ b/example/mainnet/registry.js @@ -0,0 +1,75 @@ +const { + addressToScript, + rawTransactionToHash, + scriptToHash, + serializeWitnessArgs, +} = require('@nervosnetwork/ckb-sdk-utils') +const { Collector, Aggregator, getAlwaysSuccessLock, generateRegisterCotaTx, FEE } = require('@nervina-labs/cota-sdk') + +// AliceMainnet +const TEST_PRIVATE_KEY = '0x-example' +const TEST_ADDRESS = 'ckb1qyqxx0xdw7g67eu35nuj0f237eg8skpdctuqwx39xm' + +const secp256k1CellDep = isMainnet => { + if (isMainnet) { + return { + outPoint: { + txHash: '0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c', + index: '0x0', + }, + depType: 'depGroup', + } + } + return { + outPoint: { + txHash: '0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37', + index: '0x0', + }, + depType: 'depGroup', + } +} + +const run = async () => { + // True for mainnet and false for testnet + const isMainnet = true + + const service = { + collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }), + aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }), + } + const ckb = service.collector.getCkb() + const provideCKBLock = addressToScript(TEST_ADDRESS) + const unregisteredCotaLock = addressToScript(TEST_ADDRESS) + + let rawTx = await generateRegisterCotaTx(service, [unregisteredCotaLock], provideCKBLock, FEE, isMainnet) + rawTx.cellDeps.push(secp256k1CellDep(isMainnet)) + + const registryLock = getAlwaysSuccessLock(isMainnet) + + let keyMap = new Map() + keyMap.set(scriptToHash(registryLock), '') + keyMap.set(scriptToHash(provideCKBLock), TEST_PRIVATE_KEY) + + const cells = rawTx.inputs.map((input, index) => ({ + outPoint: input.previousOutput, + lock: index === 0 ? registryLock : provideCKBLock, + })) + + const transactionHash = rawTransactionToHash(rawTx) + + const signedWitnesses = ckb.signWitnesses(keyMap)({ + transactionHash, + witnesses: rawTx.witnesses, + inputCells: cells, + skipMissingKeys: true, + }) + const signedTx = { + ...rawTx, + witnesses: signedWitnesses.map(witness => (typeof witness === 'string' ? witness : serializeWitnessArgs(witness))), + } + console.log(JSON.stringify(signedTx)) + let txHash = await ckb.rpc.sendTransaction(signedTx, 'passthrough') + console.log(`Register cota cell tx has been sent with tx hash ${txHash}`) +} + +run() diff --git a/example/mainnet/transfer.js b/example/mainnet/transfer.js new file mode 100644 index 0000000..fb30088 --- /dev/null +++ b/example/mainnet/transfer.js @@ -0,0 +1,56 @@ +const { addressToScript, serializeScript } = require('@nervosnetwork/ckb-sdk-utils') +const { Collector, Aggregator, generateTransferCotaTx, FEE } = require('@nervina-labs/cota-sdk') + +const TEST_ADDRESS = 'ckb1qyqxx0xdw7g67eu35nuj0f237eg8skpdctuqwx39xm' +const RECEIVER_PRIVATE_KEY = '0x-example' +const RECEIVER_ADDRESS = 'ckb1qyqxx0xdw7g67eu35nuj0f237eg8skpdctuqwx39xm' +const OTHER_ADDRESS = 'ckb1qyq0xt2728kgl0pfvqgvul92209z7vkxwezsmqz650' + +const secp256k1CellDep = isMainnet => { + if (isMainnet) { + return { + outPoint: { + txHash: '0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c', + index: '0x0', + }, + depType: 'depGroup', + } + } + return { + outPoint: { + txHash: '0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37', + index: '0x0', + }, + depType: 'depGroup', + } +} + +const run = async () => { + // True for mainnet and false for testnet + const isMainnet = true + + const service = { + collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }), + aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }), + } + const ckb = service.collector.getCkb() + const cotaLock = addressToScript(RECEIVER_ADDRESS) + const withdrawLock = addressToScript(TEST_ADDRESS) + + const transfers = [ + { + cotaId: '0xae223946058e5b148045d11483df60b36dc28a30', + tokenIndex: '0x00000000', + toLockScript: serializeScript(addressToScript(OTHER_ADDRESS)), + }, + ] + let rawTx = await generateTransferCotaTx(service, cotaLock, withdrawLock, transfers, FEE, isMainnet) + rawTx.cellDeps.push(secp256k1CellDep(isMainnet)) + + const signedTx = ckb.signTransaction(RECEIVER_PRIVATE_KEY)(rawTx) + console.log(JSON.stringify(signedTx)) + let txHash = await ckb.rpc.sendTransaction(signedTx, 'passthrough') + console.info(`Transfer cota nft tx has been sent with tx hash ${txHash}`) +} + +run() diff --git a/example/mainnet/yarn.lock b/example/mainnet/yarn.lock new file mode 100644 index 0000000..f7bb55e --- /dev/null +++ b/example/mainnet/yarn.lock @@ -0,0 +1,238 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@nervina-labs/cota-sdk@0.4.7": + version "0.4.7" + resolved "https://registry.yarnpkg.com/@nervina-labs/cota-sdk/-/cota-sdk-0.4.7.tgz#889a8ec8e9f5e00749010967cf458e6f54e10c5a" + integrity sha512-qTCf/pb+WvSrtlryDJGoVBQU4WjihQ8ryIUHpbg0aelndaWSSiQpNL86yY7bp5WbkAs6yejxOnxO/Jo+gqSO0Q== + dependencies: + "@nervosnetwork/ckb-sdk-core" "^0.102.3" + "@nervosnetwork/ckb-sdk-utils" "^0.102.3" + "@nervosnetwork/ckb-types" "^0.102.3" + axios "^0.27.2" + camelcase-keys "^7.0.2" + convert-keys "1.3.4" + +"@nervosnetwork/ckb-sdk-core@^0.102.3": + version "0.102.3" + resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-core/-/ckb-sdk-core-0.102.3.tgz#e312169df0a0fab390e5d562fa82952749d2c4d0" + integrity sha512-DLbynmSTnuCcw/cCST7nmNilCuvqprDpLtloRj99Ml1ozaL2OX9KVfSCcLXnvymTMhrLmMoG9zoSSgD9u2JJ+g== + dependencies: + "@nervosnetwork/ckb-sdk-rpc" "0.102.3" + "@nervosnetwork/ckb-sdk-utils" "0.102.3" + "@nervosnetwork/ckb-types" "0.102.3" + tslib "2.3.1" + +"@nervosnetwork/ckb-sdk-rpc@0.102.3": + version "0.102.3" + resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-rpc/-/ckb-sdk-rpc-0.102.3.tgz#a5ebf859c5818afedb115b3a3ffb457e2e9f39be" + integrity sha512-zBix6CH86V8vuWOQKVcIE5fMPumBtmyfQGUupOlwzpBNuNpeGu4ErHl3EnwBMRoYXmRsVgBwfFk/tdAG9plicw== + dependencies: + "@nervosnetwork/ckb-sdk-utils" "0.102.3" + axios "0.21.4" + tslib "2.3.1" + +"@nervosnetwork/ckb-sdk-utils@0.102.3", "@nervosnetwork/ckb-sdk-utils@^0.102.3": + version "0.102.3" + resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-utils/-/ckb-sdk-utils-0.102.3.tgz#839bfc6997861f747b1e2f70c633d82cbfdb9950" + integrity sha512-Szuwpq1Bqp2J37tDJQrk59oHYHTnf8LA8CCKmWy2PUoLKYX9kY/aMujKgw1/Dp8YqNDxWzJNBwaJ5FvQUp4fBA== + dependencies: + "@nervosnetwork/ckb-types" "0.102.3" + bech32 "2.0.0" + elliptic "6.5.4" + jsbi "3.1.3" + tslib "2.3.1" + +"@nervosnetwork/ckb-types@0.102.3", "@nervosnetwork/ckb-types@^0.102.3": + version "0.102.3" + resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-types/-/ckb-types-0.102.3.tgz#159c05b02f40f2045da918856f6e7a627c673147" + integrity sha512-iOpTt0p8ubyBMYxZuXu+SVD1p9ekAsMTjG5XlePkHZj3eNX3W9cYwHcPJJlTXi4K/2XOZ3tWHjBFY3PVWr+dHg== + +asynckit@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" + integrity sha1-x57Zf380y48robyXkLzDZkdLS3k= + +axios@0.21.4: + version "0.21.4" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575" + integrity sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg== + dependencies: + follow-redirects "^1.14.0" + +axios@^0.27.2: + version "0.27.2" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972" + integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ== + dependencies: + follow-redirects "^1.14.9" + form-data "^4.0.0" + +bech32@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/bech32/-/bech32-2.0.0.tgz#078d3686535075c8c79709f054b1b226a133b355" + integrity sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg== + +bn.js@^4.11.9: + version "4.12.0" + resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88" + integrity sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA== + +brorand@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/brorand/-/brorand-1.1.0.tgz#12c25efe40a45e3c323eb8675a0a0ce57b22371f" + integrity sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8= + +camelcase-keys@^7.0.2: + version "7.0.2" + resolved "https://registry.yarnpkg.com/camelcase-keys/-/camelcase-keys-7.0.2.tgz#d048d8c69448745bb0de6fc4c1c52a30dfbe7252" + integrity sha512-Rjs1H+A9R+Ig+4E/9oyB66UC5Mj9Xq3N//vcLf2WzgdTi/3gUu3Z9KoqmlrEG4VuuLK8wJHofxzdQXz/knhiYg== + dependencies: + camelcase "^6.3.0" + map-obj "^4.1.0" + quick-lru "^5.1.1" + type-fest "^1.2.1" + +camelcase@^6.3.0: + version "6.3.0" + resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.3.0.tgz#5685b95eb209ac9c0c177467778c9c84df58ba9a" + integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA== + +combined-stream@^1.0.8: + version "1.0.8" + resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" + integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== + dependencies: + delayed-stream "~1.0.0" + +convert-keys@1.3.4: + version "1.3.4" + resolved "https://registry.yarnpkg.com/convert-keys/-/convert-keys-1.3.4.tgz#9285f9967beb386a61203f22ab1c7baaddd9d8ea" + integrity sha512-+ltki+EUagotW/x7r+15nuHyk4nzcSkBk1lZpmbHjscF2E9ZmNErgV7K18LNshB0qglECcsnwy29ODlJ0pI0KA== + dependencies: + lodash.camelcase "^4.3.0" + lodash.forown "^4.4.0" + lodash.isplainobject "^4.0.6" + lodash.snakecase "^4.1.1" + +delayed-stream@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" + integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk= + +elliptic@6.5.4: + version "6.5.4" + resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.4.tgz#da37cebd31e79a1367e941b592ed1fbebd58abbb" + integrity sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ== + dependencies: + bn.js "^4.11.9" + brorand "^1.1.0" + hash.js "^1.0.0" + hmac-drbg "^1.0.1" + inherits "^2.0.4" + minimalistic-assert "^1.0.1" + minimalistic-crypto-utils "^1.0.1" + +follow-redirects@^1.14.0, follow-redirects@^1.14.9: + version "1.15.0" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.0.tgz#06441868281c86d0dda4ad8bdaead2d02dca89d4" + integrity sha512-aExlJShTV4qOUOL7yF1U5tvLCB0xQuudbf6toyYA0E/acBNw71mvjFTnLaRp50aQaYocMR0a/RMMBIHeZnGyjQ== + +form-data@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" + integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.8" + mime-types "^2.1.12" + +hash.js@^1.0.0, hash.js@^1.0.3: + version "1.1.7" + resolved "https://registry.yarnpkg.com/hash.js/-/hash.js-1.1.7.tgz#0babca538e8d4ee4a0f8988d68866537a003cf42" + integrity sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA== + dependencies: + inherits "^2.0.3" + minimalistic-assert "^1.0.1" + +hmac-drbg@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1" + integrity sha1-0nRXAQJabHdabFRXk+1QL8DGSaE= + dependencies: + hash.js "^1.0.3" + minimalistic-assert "^1.0.0" + minimalistic-crypto-utils "^1.0.1" + +inherits@^2.0.3, inherits@^2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" + integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== + +jsbi@3.1.3: + version "3.1.3" + resolved "https://registry.yarnpkg.com/jsbi/-/jsbi-3.1.3.tgz#f024b340032f7c7caaa6ca4b32b55e8d33f6e897" + integrity sha512-nBJqA0C6Qns+ZxurbEoIR56wyjiUszpNy70FHvxO5ervMoCbZVE3z3kxr5nKGhlxr/9MhKTSUBs7cAwwuf3g9w== + +lodash.camelcase@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6" + integrity sha1-soqmKIorn8ZRA1x3EfZathkDMaY= + +lodash.forown@^4.4.0: + version "4.4.0" + resolved "https://registry.yarnpkg.com/lodash.forown/-/lodash.forown-4.4.0.tgz#85115cf04f73ef966eced52511d3893cc46683af" + integrity sha1-hRFc8E9z75ZuztUlEdOJPMRmg68= + +lodash.isplainobject@^4.0.6: + version "4.0.6" + resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb" + integrity sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs= + +lodash.snakecase@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz#39d714a35357147837aefd64b5dcbb16becd8f8d" + integrity sha1-OdcUo1NXFHg3rv1ktdy7Fr7Nj40= + +map-obj@^4.1.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/map-obj/-/map-obj-4.3.0.tgz#9304f906e93faae70880da102a9f1df0ea8bb05a" + integrity sha512-hdN1wVrZbb29eBGiGjJbeP8JbKjq1urkHJ/LIP/NY48MZ1QVXUsQBV1G1zvYFHn1XE06cwjBsOI2K3Ulnj1YXQ== + +mime-db@1.52.0: + version "1.52.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70" + integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg== + +mime-types@^2.1.12: + version "2.1.35" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a" + integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw== + dependencies: + mime-db "1.52.0" + +minimalistic-assert@^1.0.0, minimalistic-assert@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7" + integrity sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A== + +minimalistic-crypto-utils@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz#f6c00c1c0b082246e5c4d99dfb8c7c083b2b582a" + integrity sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo= + +quick-lru@^5.1.1: + version "5.1.1" + resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-5.1.1.tgz#366493e6b3e42a3a6885e2e99d18f80fb7a8c932" + integrity sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA== + +tslib@2.3.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.1.tgz#e8a335add5ceae51aa261d32a490158ef042ef01" + integrity sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw== + +type-fest@^1.2.1: + version "1.4.0" + resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-1.4.0.tgz#e9fb813fe3bf1744ec359d55d1affefa76f14be1" + integrity sha512-yGSza74xk0UG8k+pLh5oeoYirvIiWo5t0/o3zHHAO2tRDiZcxWP7fywNlXhqb6/r6sWvwi+RsyQMWhVLe4BVuA== diff --git a/example/mint.ts b/example/mint.ts index a15359d..beb5473 100644 --- a/example/mint.ts +++ b/example/mint.ts @@ -3,18 +3,28 @@ import { Collector } from '../src/collector' import { Aggregator } from '../src/aggregator' import { generateMintCotaTx } from '../src/service/cota' import { MintCotaInfo, Service, FEE } from '../src' -import CKB from '@nervosnetwork/ckb-sdk-core' const TEST_PRIVATE_KEY = '0xc5bd09c9b954559c70a77d68bde95369e2ce910556ddc20f739080cde3b62ef2' const TEST_ADDRESS = 'ckt1qyq0scej4vn0uka238m63azcel7cmcme7f2sxj5ska' -const RECEIVER_ADDRESS = 'ckt1qyqdcu8n8h5xlhecrd8ut0cf9wer6qnhfqqsnz3lw9' - -const secp256k1CellDep = async (ckb: CKB): Promise => { - const secp256k1Dep = (await ckb.loadDeps()).secp256k1Dep - return { outPoint: secp256k1Dep.outPoint, depType: 'depGroup' } +const RECEIVER_ADDRESS = 'ckt1qyqy6xew5q449zg5du7wdjhgrxschjkg3n2q8h5ycc' + +const secp256k1CellDep = (isMainnet: boolean): CKBComponents.CellDep => { + if (isMainnet) { + return { outPoint: { + txHash: "0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c", + index: "0x0", + }, depType: 'depGroup' } + } + return { outPoint: { + txHash: "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37", + index: "0x0", + }, depType: 'depGroup' } } const run = async () => { + // True for mainnet and false for testnet + const isMainnet = false + const service: Service = { collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }), aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }), @@ -41,14 +51,8 @@ const run = async () => { ], } - // Testnet - let rawTx = await generateMintCotaTx(service, mintLock, mintCotaInfo) - - // Mainnet - // let rawTx = await generateMintCotaTx(service, mintLock, mintCotaInfo, FEE, true) - - const secp256k1Dep = await secp256k1CellDep(ckb) - rawTx.cellDeps.push(secp256k1Dep) + let rawTx = await generateMintCotaTx(service, mintLock, mintCotaInfo, FEE, isMainnet) + rawTx.cellDeps.push(secp256k1CellDep(isMainnet)) const signedTx = ckb.signTransaction(TEST_PRIVATE_KEY)(rawTx) console.log(JSON.stringify(signedTx)) diff --git a/example/registry.js b/example/registry.js index 13614a2..f05c6e8 100644 --- a/example/registry.js +++ b/example/registry.js @@ -13,12 +13,23 @@ const signWitnesses = require('@nervosnetwork/ckb-sdk-core/lib/signWitnesses') const TEST_PRIVATE_KEY = '0xc5bd09c9b954559c70a77d68bde95369e2ce910556ddc20f739080cde3b62ef2' const TEST_ADDRESS = 'ckt1qyq0scej4vn0uka238m63azcel7cmcme7f2sxj5ska' -const secp256k1CellDep = async ckb => { - const secp256k1Dep = (await ckb.loadDeps()).secp256k1Dep - return { outPoint: secp256k1Dep.outPoint, depType: 'depGroup' } +const secp256k1CellDep = (isMainnet) => { + if (isMainnet) { + return { outPoint: { + txHash: "0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c", + index: "0x0", + }, depType: 'depGroup' } + } + return { outPoint: { + txHash: "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37", + index: "0x0", + }, depType: 'depGroup' } } const run = async () => { + // True for mainnet and false for testnet + const isMainnet = false + const service = { collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }), aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }), @@ -26,19 +37,11 @@ const run = async () => { const ckb = service.collector.getCkb() const provideCKBLock = addressToScript(TEST_ADDRESS) const unregisteredCotaLock = addressToScript(TEST_ADDRESS) - // Testnet - let rawTx = await generateRegisterCotaTx(service, [unregisteredCotaLock], provideCKBLock) - - // Mainnet - // let rawTx = await generateRegisterCotaTx(service, [unregisteredCotaLock], provideCKBLock, FEE, true) - - const secp256k1Dep = await secp256k1CellDep(ckb) - rawTx.cellDeps.push(secp256k1Dep) - - const registryLock = getAlwaysSuccessLock(false) + + let rawTx = await generateRegisterCotaTx(service, [unregisteredCotaLock], provideCKBLock, FEE, isMainnet) + rawTx.cellDeps.push(secp256k1CellDep(isMainnet)) - // Mainnet - // const registryLock = getAlwaysSuccessLock(true) + const registryLock = getAlwaysSuccessLock(isMainnet) let keyMap = new Map() keyMap.set(scriptToHash(registryLock), '') diff --git a/example/registry.ts b/example/registry.ts index dbacdd2..ae56fd2 100644 --- a/example/registry.ts +++ b/example/registry.ts @@ -4,18 +4,28 @@ import { Aggregator } from '../src/aggregator' import { getAlwaysSuccessLock } from '../src/constants' import { generateRegisterCotaTx } from '../src/service/registry' import { Service, FEE } from '../src' -import CKB from '@nervosnetwork/ckb-sdk-core' import signWitnesses from '@nervosnetwork/ckb-sdk-core/lib/signWitnesses' const TEST_PRIVATE_KEY = '0xc5bd09c9b954559c70a77d68bde95369e2ce910556ddc20f739080cde3b62ef2' const TEST_ADDRESS = 'ckt1qyq0scej4vn0uka238m63azcel7cmcme7f2sxj5ska' -const secp256k1CellDep = async (ckb: CKB): Promise => { - const secp256k1Dep = (await ckb.loadDeps()).secp256k1Dep - return { outPoint: secp256k1Dep.outPoint, depType: 'depGroup' } +const secp256k1CellDep = (isMainnet: boolean): CKBComponents.CellDep => { + if (isMainnet) { + return { outPoint: { + txHash: "0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c", + index: "0x0", + }, depType: 'depGroup' } + } + return { outPoint: { + txHash: "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37", + index: "0x0", + }, depType: 'depGroup' } } const run = async () => { + // True for mainnet and false for testnet + const isMainnet = false + const service: Service = { collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }), aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }), @@ -23,18 +33,11 @@ const run = async () => { const ckb = service.collector.getCkb() const provideCKBLock = addressToScript(TEST_ADDRESS) const unregisteredCotaLock = addressToScript(TEST_ADDRESS) - // Testnet - let rawTx = await generateRegisterCotaTx(service, [unregisteredCotaLock], provideCKBLock) - - // Mainnet - // let rawTx = await generateRegisterCotaTx(service, [unregisteredCotaLock], provideCKBLock, FEE, true) - const secp256k1Dep = await secp256k1CellDep(ckb) - rawTx.cellDeps.push(secp256k1Dep) - const registryLock = getAlwaysSuccessLock(false) + let rawTx = await generateRegisterCotaTx(service, [unregisteredCotaLock], provideCKBLock, FEE, isMainnet) + rawTx.cellDeps.push(secp256k1CellDep(isMainnet)) - // Mainnet - // const registryLock = getAlwaysSuccessLock(true) + const registryLock = getAlwaysSuccessLock(isMainnet) let keyMap = new Map() keyMap.set(scriptToHash(registryLock), '') diff --git a/example/transfer-update.ts b/example/transfer-update.ts index 6d519bc..cdc1356 100644 --- a/example/transfer-update.ts +++ b/example/transfer-update.ts @@ -3,19 +3,29 @@ import { Collector } from '../src/collector' import { Aggregator } from '../src/aggregator' import { generateTransferUpdateCotaTx } from '../src/service/cota' import { Service, TransferUpdate, FEE } from '../src' -import CKB from '@nervosnetwork/ckb-sdk-core' const TEST_ADDRESS = 'ckt1qyq0scej4vn0uka238m63azcel7cmcme7f2sxj5ska' -const RECEIVER_PRIVATE_KEY = '0xcf56c11ce3fbec627e5118acd215838d1f9c5048039792d42143f933cde76311' -const RECEIVER_ADDRESS = 'ckt1qyqdcu8n8h5xlhecrd8ut0cf9wer6qnhfqqsnz3lw9' +const RECEIVER_PRIVATE_KEY = '0xf0d72b5e3a27e603efb304aa16608ba3e480cb1c6790bced80fb82c53a822cee' +const RECEIVER_ADDRESS = 'ckt1qyqy6xew5q449zg5du7wdjhgrxschjkg3n2q8h5ycc' const OTHER_ADDRESS = 'ckt1qyqz8vxeyrv4nur4j27ktp34fmwnua9wuyqqggd748' -const secp256k1CellDep = async (ckb: CKB): Promise => { - const secp256k1Dep = (await ckb.loadDeps()).secp256k1Dep - return { outPoint: secp256k1Dep.outPoint, depType: 'depGroup' } +const secp256k1CellDep = (isMainnet: boolean): CKBComponents.CellDep => { + if (isMainnet) { + return { outPoint: { + txHash: "0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c", + index: "0x0", + }, depType: 'depGroup' } + } + return { outPoint: { + txHash: "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37", + index: "0x0", + }, depType: 'depGroup' } } const run = async () => { + // True for mainnet and false for testnet + const isMainnet = false + const service: Service = { collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }), aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }), @@ -27,20 +37,14 @@ const run = async () => { const transfers: TransferUpdate[] = [ { cotaId: '0xc27328c95e27723d42770261d05355977aa5c89a', - tokenIndex: '0x00000001', + tokenIndex: '0x00000004', toLockScript: serializeScript(addressToScript(OTHER_ADDRESS)), state: '0x00', characteristic: '0x2525250505050505050505050505050505050505', }, ] - // Testnet - let rawTx = await generateTransferUpdateCotaTx(service, cotaLock, withdrawLock, transfers) - - // Mainnet - // let rawTx = await generateTransferUpdateCotaTx(service, cotaLock, withdrawLock, transfers, FEE, true) - - const secp256k1Dep = await secp256k1CellDep(ckb) - rawTx.cellDeps.push(secp256k1Dep) + let rawTx = await generateTransferUpdateCotaTx(service, cotaLock, withdrawLock, transfers, FEE, isMainnet) + rawTx.cellDeps.push(secp256k1CellDep(isMainnet)) const signedTx = ckb.signTransaction(RECEIVER_PRIVATE_KEY)(rawTx) console.log(JSON.stringify(signedTx)) diff --git a/example/transfer.ts b/example/transfer.ts index 53898e2..3b6513c 100644 --- a/example/transfer.ts +++ b/example/transfer.ts @@ -3,19 +3,29 @@ import { Collector } from '../src/collector' import { Aggregator } from '../src/aggregator' import { generateTransferCotaTx } from '../src/service/cota' import { TransferWithdrawal, Service, FEE } from '../src' -import CKB from '@nervosnetwork/ckb-sdk-core' const TEST_ADDRESS = 'ckt1qyq0scej4vn0uka238m63azcel7cmcme7f2sxj5ska' -const RECEIVER_PRIVATE_KEY = '0xcf56c11ce3fbec627e5118acd215838d1f9c5048039792d42143f933cde76311' -const RECEIVER_ADDRESS = 'ckt1qyqdcu8n8h5xlhecrd8ut0cf9wer6qnhfqqsnz3lw9' +const RECEIVER_PRIVATE_KEY = '0xf0d72b5e3a27e603efb304aa16608ba3e480cb1c6790bced80fb82c53a822cee' +const RECEIVER_ADDRESS = 'ckt1qyqy6xew5q449zg5du7wdjhgrxschjkg3n2q8h5ycc' const OTHER_ADDRESS = 'ckt1qyqz8vxeyrv4nur4j27ktp34fmwnua9wuyqqggd748' -const secp256k1CellDep = async (ckb: CKB): Promise => { - const secp256k1Dep = (await ckb.loadDeps()).secp256k1Dep - return { outPoint: secp256k1Dep.outPoint, depType: 'depGroup' } +const secp256k1CellDep = (isMainnet: boolean): CKBComponents.CellDep => { + if (isMainnet) { + return { outPoint: { + txHash: "0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c", + index: "0x0", + }, depType: 'depGroup' } + } + return { outPoint: { + txHash: "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37", + index: "0x0", + }, depType: 'depGroup' } } const run = async () => { + // True for mainnet and false for testnet + const isMainnet = false + const service: Service = { collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }), aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }), @@ -27,18 +37,12 @@ const run = async () => { const transfers: TransferWithdrawal[] = [ { cotaId: '0xc27328c95e27723d42770261d05355977aa5c89a', - tokenIndex: "0x00000004", + tokenIndex: "0x00000013", toLockScript: serializeScript(addressToScript(OTHER_ADDRESS)), }, ] - // Testnet - let rawTx = await generateTransferCotaTx(service, cotaLock, withdrawLock, transfers) - - // Mainnet - // let rawTx = await generateTransferCotaTx(service, cotaLock, withdrawLock, transfers, FEE, true) - - const secp256k1Dep = await secp256k1CellDep(ckb) - rawTx.cellDeps.push(secp256k1Dep) + let rawTx = await generateTransferCotaTx(service, cotaLock, withdrawLock, transfers, FEE, isMainnet) + rawTx.cellDeps.push(secp256k1CellDep(isMainnet)) const signedTx = ckb.signTransaction(RECEIVER_PRIVATE_KEY)(rawTx) console.log(JSON.stringify(signedTx)) diff --git a/example/update.ts b/example/update.ts index 1347d60..febf462 100644 --- a/example/update.ts +++ b/example/update.ts @@ -3,43 +3,47 @@ import { Collector } from '../src/collector' import { Aggregator } from '../src/aggregator' import { generateUpdateCotaTx } from '../src/service/cota' import { CotaNft, Service, FEE } from '../src' -import CKB from '@nervosnetwork/ckb-sdk-core' -const TEST_PRIVATE_KEY = '0xc5bd09c9b954559c70a77d68bde95369e2ce910556ddc20f739080cde3b62ef2' -const TEST_ADDRESS = 'ckt1qyq0scej4vn0uka238m63azcel7cmcme7f2sxj5ska' +const RECEIVER_PRIVATE_KEY = '0xf0d72b5e3a27e603efb304aa16608ba3e480cb1c6790bced80fb82c53a822cee' +const RECEIVER_ADDRESS = 'ckt1qyqy6xew5q449zg5du7wdjhgrxschjkg3n2q8h5ycc' -const secp256k1CellDep = async (ckb: CKB): Promise => { - const secp256k1Dep = (await ckb.loadDeps()).secp256k1Dep - return { outPoint: secp256k1Dep.outPoint, depType: 'depGroup' } +const secp256k1CellDep = (isMainnet: boolean): CKBComponents.CellDep => { + if (isMainnet) { + return { outPoint: { + txHash: "0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c", + index: "0x0", + }, depType: 'depGroup' } + } + return { outPoint: { + txHash: "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37", + index: "0x0", + }, depType: 'depGroup' } } const run = async () => { + // True for mainnet and false for testnet + const isMainnet = false + const service: Service = { collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }), aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }), } const ckb = service.collector.getCkb() - const cotaLock = addressToScript(TEST_ADDRESS) + const cotaLock = addressToScript(RECEIVER_ADDRESS) const cotaNfts: CotaNft[] = [ { cotaId: '0xc27328c95e27723d42770261d05355977aa5c89a', - tokenIndex: '0x00000000', + tokenIndex: '0x00000002', state: '0x00', characteristic: '0x0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a', }, ] - // Testnet - let rawTx = await generateUpdateCotaTx(service, cotaLock, cotaNfts) - - // Mainnet - // let rawTx = await generateUpdateCotaTx(service, cotaLock, cotaNfts, FEE, true) - - const secp256k1Dep = await secp256k1CellDep(ckb) - rawTx.cellDeps.push(secp256k1Dep) + let rawTx = await generateUpdateCotaTx(service, cotaLock, cotaNfts, FEE, isMainnet) + rawTx.cellDeps.push(secp256k1CellDep(isMainnet)) - const signedTx = ckb.signTransaction(TEST_PRIVATE_KEY)(rawTx) + const signedTx = ckb.signTransaction(RECEIVER_PRIVATE_KEY)(rawTx) console.log(JSON.stringify(signedTx)) let txHash = await ckb.rpc.sendTransaction(signedTx, 'passthrough') console.info(`Update cota nft tx has been sent with tx hash ${txHash}`) diff --git a/example/withdraw.ts b/example/withdraw.ts index 3984e27..f607524 100644 --- a/example/withdraw.ts +++ b/example/withdraw.ts @@ -3,18 +3,28 @@ import { Collector } from '../src/collector' import { Aggregator } from '../src/aggregator' import { generateWithdrawCotaTx } from '../src/service/cota' import { Service, TransferWithdrawal, FEE } from '../src' -import CKB from '@nervosnetwork/ckb-sdk-core' const TEST_ADDRESS = 'ckt1qyq0scej4vn0uka238m63azcel7cmcme7f2sxj5ska' -const RECEIVER_PRIVATE_KEY = '0xcf56c11ce3fbec627e5118acd215838d1f9c5048039792d42143f933cde76311' -const RECEIVER_ADDRESS = 'ckt1qyqdcu8n8h5xlhecrd8ut0cf9wer6qnhfqqsnz3lw9' - -const secp256k1CellDep = async (ckb: CKB): Promise => { - const secp256k1Dep = (await ckb.loadDeps()).secp256k1Dep - return { outPoint: secp256k1Dep.outPoint, depType: 'depGroup' } +const RECEIVER_PRIVATE_KEY = '0xf0d72b5e3a27e603efb304aa16608ba3e480cb1c6790bced80fb82c53a822cee' +const RECEIVER_ADDRESS = 'ckt1qyqy6xew5q449zg5du7wdjhgrxschjkg3n2q8h5ycc' + +const secp256k1CellDep = (isMainnet: boolean): CKBComponents.CellDep => { + if (isMainnet) { + return { outPoint: { + txHash: "0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c", + index: "0x0", + }, depType: 'depGroup' } + } + return { outPoint: { + txHash: "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37", + index: "0x0", + }, depType: 'depGroup' } } const run = async () => { + // True for mainnet and false for testnet + const isMainnet = false + const service: Service = { collector: new Collector({ ckbNodeUrl: 'http://localhost:8114', ckbIndexerUrl: 'http://localhost:8116' }), aggregator: new Aggregator({ registryUrl: 'http://localhost:3050', cotaUrl: 'http://localhost:3030' }), @@ -26,19 +36,13 @@ const run = async () => { const withdrawals: TransferWithdrawal[] = [ { cotaId: '0xc27328c95e27723d42770261d05355977aa5c89a', - tokenIndex: '0x00000000', + tokenIndex: '0x00000003', toLockScript: serializeScript(toLock), }, ] - // Testnet - let rawTx = await generateWithdrawCotaTx(service, withdrawLock, withdrawals) - - // Mainnet - // let rawTx = await generateWithdrawCotaTx(service, withdrawLock, withdrawals, FEE, true) - - const secp256k1Dep = await secp256k1CellDep(ckb) - rawTx.cellDeps.push(secp256k1Dep) + let rawTx = await generateWithdrawCotaTx(service, withdrawLock, withdrawals, FEE, isMainnet) + rawTx.cellDeps.push(secp256k1CellDep(isMainnet)) const signedTx = ckb.signTransaction(RECEIVER_PRIVATE_KEY)(rawTx) console.log(JSON.stringify(signedTx)) diff --git a/package.json b/package.json index 3cb31b2..a4a8474 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nervina-labs/cota-sdk", - "version": "0.4.7", + "version": "0.4.8", "description": "The SDK of CoTA", "repository": "git@github.com:nervina-labs/cota-sdk-js.git", "author": "duanyytop ", diff --git a/src/constants/index.ts b/src/constants/index.ts index ce923b4..29eac74 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -15,7 +15,7 @@ const TestnetInfo = { } as CKBComponents.Script, CotaTypeDep: { - outPoint: { txHash: '0x2dfcab7790f3cabffe5cb349546dac8918b409481828218cc162f9de5754116f', index: '0x0' }, + outPoint: { txHash: '0x698f2a29021ebd741b4a38b4a5f8fa3686103ba66773e7549b204a67db015ba0', index: '0x0' }, depType: 'depGroup', } as CKBComponents.CellDep,