Giter Club home page Giter Club logo

Comments (5)

Wangmmx avatar Wangmmx commented on July 25, 2024

Adding my code here:

    const nodeUrl =******
    const core = new Core(nodeUrl)
    let secp256k1Dep = await core.loadSecp256k1Dep();

    let pubKey = '0x035a27b3564c6a08337ba07f8120551d5721e9ae888bcd60df705de7509d2bc73d';
    let address = CKBUtils.pubkeyToAddress(pubKey, {prefix: 'ckt'});

    let pubKeyHash = '0x' + CKBUtils.blake160(pubKey, 'hex');
    let codeHash = secp256k1Dep.codeHash;

    let lockScript = {
        hashType: "type",
        codeHash: codeHash,
        args: pubKeyHash
    }
    let lockHash = CKBUtils.scriptToHash(lockScript);
    let unspentCells = await core.loadCells({lockHash})

    let rawTransaction = await core.generateRawTransaction({
        fromAddress: 'ckt1qyqdjvjspzuj0vjg85duwl8s9a8x32u3ddksef5eqc',
        toAddress: 'ckt1qyqwkcma99gj3zlh2wwzzd2etawegg90lepssacpmh',
        capacity: 7000000000,
        fee: 100000,
        safeMode: true,
        cells: unspentCells,
        deps: core.config.secp256k1Dep,
    })

    rawTransaction.witnesses = rawTransaction.inputs.map(() => '0x')
    rawTransaction.witnesses[0] = {
        lock: '',
        inputType: '',
        outputType: ''
    }

    let privateKey = '0x7faf9bddf383c4ac07b32f7001905975c0b91761e9794590c4e5475583362bdc'
    const signedTx = core.signTransaction(privateKey)(rawTransaction);
    const realTxHash = await core.rpc.sendTransaction(signedTx);
    console.log('The real transaction hash is:', realTxHash)

from ckb-sdk-js.

Keith-CY avatar Keith-CY commented on July 25, 2024

I've run the example and it works

const Core = require('../lib').default

const bootstrap = async () => {
  const nodeUrl = 'http://localhost:8114'
  const core = new Core(nodeUrl)
  const secp256k1Dep = await core.loadSecp256k1Dep()
  const CKBUtils = core.utils

  const pubKey = '0x035a27b3564c6a08337ba07f8120551d5721e9ae888bcd60df705de7509d2bc73d'
  // const address = CKBUtils.pubkeyToAddress(pubKey, {
  //   prefix: 'ckt',
  // })

  const pubKeyHash = `0x${CKBUtils.blake160(pubKey, 'hex')}`
  const { codeHash } = secp256k1Dep

  const lockScript = {
    hashType: 'type',
    codeHash,
    args: pubKeyHash,
  }
  const lockHash = CKBUtils.scriptToHash(lockScript)
  const unspentCells = await core.loadCells({
    lockHash,
  })

  const rawTransaction = await core.generateRawTransaction({
    fromAddress: 'ckt1qyqdjvjspzuj0vjg85duwl8s9a8x32u3ddksef5eqc',
    toAddress: 'ckt1qyqwkcma99gj3zlh2wwzzd2etawegg90lepssacpmh',
    capacity: 7000000000,
    fee: 100000,
    safeMode: true,
    cells: unspentCells,
    deps: core.config.secp256k1Dep,
  })

  rawTransaction.witnesses = rawTransaction.inputs.map(() => '0x')
  rawTransaction.witnesses[0] = {
    lock: '',
    inputType: '',
    outputType: '',
  }

  const privateKey = '0x7faf9bddf383c4ac07b32f7001905975c0b91761e9794590c4e5475583362bdc'
  const signedTx = core.signTransaction(privateKey)(rawTransaction)
  const realTxHash = await core.rpc.sendTransaction(signedTx)
  console.log('The real transaction hash is:', realTxHash)
}

bootstrap()

Could you please post the versions of ckb-sdk-js and ckb, and the signed transaction generated by the sdk here? Thanks.

from ckb-sdk-js.

Wangmmx avatar Wangmmx commented on July 25, 2024

versions:
ckb-sdk-js:0.23.1
and I will ask ckb version later.

signed transaction:
{"version":"0x0","cellDeps":[{"outPoint":{"txHash":"0xbd864a269201d7052d4eb3f753f49f7c68b8edc386afc8bb6ef3e15a05facca2","index":"0x0"},"depType":"depGroup"}],"headerDeps":[],"inputs":[{"previousOutput":{"txHash":"0x9f15aaa6be33632d0f6f70a711b72d7671ce1920330a0dee5e94e636a515fa48","index":"0x0"},"since":"0x0"}],"outputs":[{"capacity":"0x1a13b8600","lock":{"hashType":"type","codeHash":"0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8","args":"0xeb637d2951288bf7539c2135595f5d9420affe43"}},{"capacity":"0x72c9170200","lock":{"codeHash":"0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8","hashType":"type","args":"0xd9325008b927b2483d1bc77cf02f4e68ab916b6d"}}],"witnesses":["0x9aec5105f107c49f77db285a28edc007c2c9e60dd36a77084565f08c737d11b305fb5b5bf896c72009a40c8914b429fd961b97be80279f4e28b3d0d29abe6500000000000c000bec00"],"outputsData":["0x","0x"]}

from ckb-sdk-js.

Keith-CY avatar Keith-CY commented on July 25, 2024

versions:
ckb-sdk-js:0.23.1
and I will ask ckb version later.

signed transaction:
{"version":"0x0","cellDeps":[{"outPoint":{"txHash":"0xbd864a269201d7052d4eb3f753f49f7c68b8edc386afc8bb6ef3e15a05facca2","index":"0x0"},"depType":"depGroup"}],"headerDeps":[],"inputs":[{"previousOutput":{"txHash":"0x9f15aaa6be33632d0f6f70a711b72d7671ce1920330a0dee5e94e636a515fa48","index":"0x0"},"since":"0x0"}],"outputs":[{"capacity":"0x1a13b8600","lock":{"hashType":"type","codeHash":"0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8","args":"0xeb637d2951288bf7539c2135595f5d9420affe43"}},{"capacity":"0x72c9170200","lock":{"codeHash":"0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8","hashType":"type","args":"0xd9325008b927b2483d1bc77cf02f4e68ab916b6d"}}],"witnesses":["0x9aec5105f107c49f77db285a28edc007c2c9e60dd36a77084565f08c737d11b305fb5b5bf896c72009a40c8914b429fd961b97be80279f4e28b3d0d29abe6500000000000c000bec00"],"outputsData":["0x","0x"]}

If the version of CKB is v0.24.*, I guess upgrading the SDK to v0.24.0 will fix this error.

The signature has changed in v0.24.

from ckb-sdk-js.

Wangmmx avatar Wangmmx commented on July 25, 2024

versions:
ckb-sdk-js:0.23.1
and I will ask ckb version later.

signed transaction:
{"version":"0x0","cellDeps":[{"outPoint":{"txHash":"0xbd864a269201d7052d4eb3f753f49f7c68b8edc386afc8bb6ef3e15a05facca2","index":"0x0"},"depType":"depGroup"}],"headerDeps":[],"inputs":[{"previousOutput":{"txHash":"0x9f15aaa6be33632d0f6f70a711b72d7671ce1920330a0dee5e94e636a515fa48","index":"0x0"},"since":"0x0"}],"outputs":[{"capacity":"0x1a13b8600","lock":{"hashType":"type","codeHash":"0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8","args":"0xeb637d2951288bf7539c2135595f5d9420affe43"}},{"capacity":"0x72c9170200","lock":{"codeHash":"0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8","hashType":"type","args":"0xd9325008b927b2483d1bc77cf02f4e68ab916b6d"}}],"witnesses":["0x9aec5105f107c49f77db285a28edc007c2c9e60dd36a77084565f08c737d11b305fb5b5bf896c72009a40c8914b429fd961b97be80279f4e28b3d0d29abe6500000000000c000bec00"],"outputsData":["0x","0x"]}

If the version of CKB is v0.24.*, I guess upgrading the SDK to v0.24.0 will fix this error.

The signature has changed in v0.24.

I update the version and it works! Thanks alot

from ckb-sdk-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.