Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sendTransactionError: code:-3 message:"Script(ValidationFailure(-2) #383

Closed
Wangmmx opened this issue Nov 6, 2019 · 5 comments
Closed
Assignees

Comments

@Wangmmx
Copy link

Wangmmx commented Nov 6, 2019

I have a problem when sending transaction, I followed the example of building a trading, only modified address and private key

https://github.com/nervosnetwork/ckb-sdk-js/blob/develop/packages/ckb-sdk-core/examples/sendTransaction.js

What is the clear mistake? thanks!

@Wangmmx
Copy link
Author

Wangmmx commented Nov 6, 2019

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)

@Keith-CY
Copy link
Member

Keith-CY commented Nov 6, 2019

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.

@Wangmmx
Copy link
Author

Wangmmx commented Nov 6, 2019

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"]}

@Keith-CY
Copy link
Member

Keith-CY commented Nov 6, 2019

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.

@Wangmmx
Copy link
Author

Wangmmx commented Nov 6, 2019

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

@Wangmmx Wangmmx closed this as completed Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants