Git Product home page Git Product logo

ckb-sdk-js's Introduction

⚠️ This SDK is obsolete and maintained passively. Please check Lumos which is updated actively.


CKB SDK JavaScript

Service Master Develop
Unit Tests Unit Tests Unit Tests
Coverage Codecov Codecov

NPM Package Quality License Telegram Group SNYK Deploy Docs

JavaScript SDK for Nervos CKB.

The ckb-sdk-js is still under development and aim for providing low-level APIs of data construction. You should get familiar with CKB transaction structure and RPCs before using it and design your own DApp SDK based on this one.

ToC


TypeDoc

Introduction

@nervosnetwork/ckb-sdk-core is the SDK used to interact with Nervos CKB, which is an open source project of public blockchain.

Before everything

Due to safety concern, the SDK won’t generate private keys for you. You can use openssl to generate a private key:

$ openssl rand -hex 32

For other cases, say, you're going to generate it in a JavaScript Project(Please don't), Elliptic may be the one you can use.

About Nervos CKB

Nervos CKB is the layer 1 of Nervos Network, a public blockchain with PoW and cell model.

Nervos project defines a suite of scalable and interoperable blockchain protocols. Nervos CKB uses those protocols to create a self-evolving distributed network with a novel economic model, data model and more.

Notice: The ckb process will send stack trace to sentry on Rust panics. This is enabled by default before mainnet, which can be opted out by setting the option dsn to empty in the config file.

About @nervosnetwork/ckb-sdk-core

@nervosnetwork/ckb-sdk-core is an SDK implemented by JavaScript, and published in NPM Registry, which provides APIs for developers to send requests to the CKB blockchain.

This SDK can be used both in Browsers and Node.js as it's source code is implemented by TypeScript, which is a superset of JavaScript and compiled into ES6. For some browsers that have old versions, some polyfills might be injected.

Prerequisites

We are going to use yarn for the next steps, which is similar to npm, so feel free to pick one.

For the developers who are interested in contribution.

Installation

$ yarn add @nervosnetwork/ckb-sdk-core # install the SDK into your project

Modules

This SDK includes several modules:

RPC Code

Used to send RPC request to the CKB, the list could be found in CKB Project

Interfaces could be found in DefaultRPC class in this module.

Utils Code

The Utils module provides useful methods for other modules.

Types Code

The Types module used to provide the type definition of CKB Components according to the CKB Project.

CKB Project compiles to the snake case convetion, which listed in the types/CKB_RPC in the RPC module.

TypeScript compiles to the PascalCase convention, which listed in this module.

CORE

All the modules above are integrated into the core module. You can find rpc and utils in the core instance.

To use the core module, you need to import it in your project and instantiate it with a node object. For now, the node object only contains one field named url, the URI of the blockchain node your are going to communicate with.

const CKB = require('@nervosnetwork/ckb-sdk-core').default

const nodeUrl = 'http://localhost:8114'

const ckb = new CKB(nodeUrl)

After that you can use the ckb object to generate addresses, send requests, etc.

RPC

Basic RPC

Please see Basic RPC

Batch Request

/**
 * The following batch includes two requests
 *   1. getBlock('0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee')
 *   2. getTransactionsByLockHash('0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', '0x0', '0x1)
 */
const batch = rpc.createBatchRequest([
  ['getBlock', '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'],
  ['getTransactionsByLockHash', '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', '0x0', '0x1'],
])

/**
 * Add a request and the batch should include three requests
 *  1. getBlock('0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee')
 *  2. getTransactionsByLockHash('0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', '0x0', '0x1)
 *  3. getTransactionsByLockHash('0xcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc', '0x0', '0x1)
 */
batch.add(
  'getTransactionsByLockHash',
  '0xcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
  '0x0',
  '0x1',
)

/**
 * Remove a request by index and the batch should include two requests
 *  1. getBlock('0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee')
 *  2. getTransactionsByLockHash('0xcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc', '0x0', '0x1)
 */
batch.remove(1)

/**
 * Send the batch request
 */
batch.exec().then(console.log)
// [
//   { "header": { }, "uncles": [], "transactions": [], "proposals": [] },
//   [ { "consumedBy": { }, "createdBy": { } } ]
// ]

// chaning usage
batch.add().remove().exec()

Persistent Connection

Please add httpAgent or httpsAgent to enable the persistent connection.

If the SDK is running in Node.js, the following steps make the persistent connection available.

// HTTP Agent
const http = require('http')
const httpAgent = new http.Agent({ keepAlive: true })
ckb.rpc.setNode({ httpAgent })

// HTTPS Agent
const https = require('https')
const httpsAgent = new https.Agent({ keepAlive: true })
ckb.rpc.setNode({ httpsAgent })

Utils

Most used utilities

Errors

  1. RPC Errors

The rpc module will throw an error when the result contains an error field, you need to handle it manually.

Examples

  1. Send Simple Transaction
  2. Send All Balance
  3. Send Transaction with multiple private key
  4. Deposit to and withdraw from Nervos DAO
  5. Send Transaction with Lumos Collector
  6. SUDT

Troubleshooting

Indexer Module

The Indexer Module in CKB has been deprecated since v0.36.0, please use ckb-indexer or lumos-indexer instead.

A simple example sendTransactionWithLumosCollector of wokring with lumos has beed added.

Development Process

This project used lerna for packages management, which needs to be bootstrapped by the following steps:

$ yarn add lerna --exact --ignore-workspace-root-check # to install the lerna package in this project, could be skipped if the lerna has been installed globally
$ npx lerna bootstrap # install the depedencies and link the packages in the project
$ yarn run tsc # build packages with tsc command

After the second step, namely the bootstrap, all module packages are linked together, and used as in one package.

ckb-sdk-js's People

Contributors

ashchan avatar classicalliu avatar cosinlink avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar duanyytop avatar happypeter avatar jeffreyma597 avatar keith-cy avatar louzhixian avatar luckyyang avatar mine77 avatar orangemio avatar painterpuppets avatar qftgtr avatar snyk-bot avatar xwartz avatar yanguoyu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ckb-sdk-js's Issues

How to send tx in production or get balance?

It's example with loadCells method, but with warning: "This method is only for demo, don't use it in production"
How to create and send tx in production? Or get balance for account?

The balance is sufficient but cannot be transferred

I used an unspent cell to transfer 3424540000 capacity, but the RPC returned Error: {"code":-3,"message":"Transaction(InsufficientCellCapacity)"}.

The picture below is my transfer capacity (0xcc1e5560 - 3424540000):
image

Below is the available cell I queried using loadCells(0x8bb2c97000 - 600000000000):
image

This is RPC respoonse result:
image

jsonScriptToTypeHash doubt

I use ckb-sdk-js to generate ckb address.
Use it like this:
image

The privateKey is different every time, but the address always is
2c77e61b5ef14aa2d8b9f54cb53247df69383b7bbffa8ac10797b95bcc0fbf66.

This is what @cezres once archived, it work well.

image

Can you point out my mistake ? @Keith-CY

merkle_tree

I found that the implementation of nervous merkle tree is unique. I cannot find the same third-party library's JavaScript implementation. Can you provide this method in this repository?Thank you.

0.36.0 doesn't compile with typescript 4.0.3

In a typescript 4.0.3 project, as soon as I add @nervosnetwork/ckb-sdk-core": "^0.36.0" to my package.json I get when I try to compile the project:

node_modules/@nervosnetwork/ckb-sdk-core/types/global.d.ts:58:13 - error TS2430: Interface 'Output' incorrectly extends interface 'CellOutput'.
  Types of property 'capacity' are incompatible.
    Type 'string | bigint' is not assignable to type 'string'.
      Type 'bigint' is not assignable to type 'string'.

58   interface Output extends CKBComponents.CellOutput {
               ~~~~~~

Any way to fix this before 0.37.0?

It's quite annoying as it forces me to turn on skipLibCheck for the whole project.

Duplicate transaction error

I am sending ckb using the sendtransaction function of ckb-sdk-js.

However, sending the same amount to the same address within a short period of time will result in a depulicate transaction error. I think that the same transaction should not be made because the previous cell was used. Is there any way to solve this?

For reference, live cells are managed through lumos/indexer.

a bug in generateRawTransaction which might cause tx failure

https://github.com/nervosnetwork/ckb-sdk-js/blob/491bf1e86b35fb0bc50871bbdccb56ec41bdc44c/packages/ckb-sdk-core/src/generateRawTransaction.ts#L94

Imagin this:

total input capacity =100 CKB
target capacity = 70 CKB
which will leave the change output cell only 30 CKB
Since the minimal cell capacity is 63 CKB, it will cause "Insufficient Cell Capacity" error.

I think the code here should be changed to:

 if (inputCapacity > targetCapacity + targetFee + BigInt(63e8)) { 

loadSystemCell fail

latest version
example code

(node:24816) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'replace' of undefined
    at Core.<anonymous> (/home/hunjixin/project/node_modules/@nervosnetwork/ckb-sdk-core/lib/index.js:59:54)
    at Generator.next (<anonymous>)
    at fulfilled (/home/hunjixin/project/node_modules/@nervosnetwork/ckb-sdk-core/lib/index.js:4:58)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)

how to send transactions with multi private keys?

I found similar issue #362 before, but can't get the function of "generateTransactionBuilder" anymore, I push each witness from different keys into witnesses, but got an error "InvalidScript(-31)"

the witnesses looks like this "['0x550000001000000055000000550000004100000000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx','0x550000001000000055000000550000004100000000yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy', '0x', '0x']

Dao related problems, please help me to have a look

The call to deposit is successful, and the call to starwithdrawing is also successful, but the call to withdraw reports an error. What is the reason for the error? don't quite understand
This is my address: ckt1qyqw8c9g9vvemn4dk40zy0rwfw89z82h6fys07ens3

const depositOutPoint = {
  txHash: "0x201b4e60ee79934170cadc8e296e9d685c49f2b497e964417d754b88e051e2b1",
  index: "0x0"
};
const startWithDrawOutPoint = {
  txHash: "0xd5271ca8302f155bdcc69e60e967aa9eb709eb8f559f46a8b79613955626bbcf",
  index: "0x0"
};
const withdraw = async () => {
  await ckb.loadDeps();
  await loadCells();
  const tx = await ckb.generateDaoWithdrawTransaction({
    depositOutPoint,
    withdrawOutPoint: startWithDrawOutPoint,
    fee: BigInt(1000000)
  });
  console.log(tx, "tx_________");
  const signed = ckb.signTransaction(sk)(tx);
  console.log(signed, "signed______");

  const txHash = await ckb.rpc.sendTransaction(signed);
  console.log(txHash, "txHash______");
  const outPoint = {
    txHash,
    index: "0x0"
  };
  console.log(`const withdrawOutPoint = ${JSON.stringify(outPoint, null, 2)}`);
};

image
image

Blake160 in C

I am applying blake2b algorithm in c and removing last 12 bytes. But my output in c is not matching with this.

it('blake160', () => {
const fixture = {
message: '024a501efd328e062c8675f2365970728c859c592beeefd6be8ead3d901330bc01',
digest: '36c329ed630d6ce750712a477543672adab57f4c',
}
const digest = blake160(new Uint8Array(Buffer.from(fixture.message, 'hex')), 'hex')
expect(digest).toBe(fixture.digest)
})

ReferenceError: Can't find variable: BigInt

When I was in safari and ci runtime environment, it will be reported the following error:
ReferenceError: Can't find variable: BigInt

image

This problem also appeared with lower node versions, is there any solution?

相同的tx数据,通过不同的工具进行签名,witnesses不一样

我们分别用 ckb-sdk-js ckb.signTransactionckb studio 进行签名,witnesses数据不一样

交易结构如下:

const rawTx = {
  "version": "0x0",
  "cellDeps": [{
    "depType": "depGroup",
    "outPoint": {
      "txHash": "0xace5ea83c478bb866edf122ff862085789158f5cbff155b7bb5f13058555b708",
      "index": "0x0"
    }
  }, {
    "depType": "code",
    "outPoint": {
      "txHash": "0x9b08d3645320e5915c8682e591f36f951dc14a733bdaa58a5e6ccefdb9c4b5b0",
      "index": "0x0"
    }
  }],
  "headerDeps": [],
  "inputs": [{
    "since": "0x0",
    "previousOutput": {
      "txHash": "0xef7e089ba381ad4eecd64565cc739278032e84baa011d8d559394e5cadd8b898",
      "index": "0x1"
    }
  }, {
    "since": "0x0",
    "previousOutput": {
      "txHash": "0xef7e089ba381ad4eecd64565cc739278032e84baa011d8d559394e5cadd8b898",
      "index": "0x0"
    }
  }],
  "outputs": [{
    "capacity": "0xb0f387b00",
    "lock": {
      "hashType": "data",
      "codeHash": "0x0fb343953ee78c9986b091defb6252154e0bb51044fd2879fde5b27314506111",
      "args": "0xcf0c34ac8af4a2c7861b33640ecc9af4e8d338f1"
    },
    "type": null
  }, {
    "capacity": "0x22ecb25c00",
    "lock": {
      "hashType": "type",
      "codeHash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
      "args": "0xbc76e06a53193d3cb2fd0eb331237cb021fe39ea"
    },
    "type": null
  }],
  "outputsData": ["0x", "0x"],
  "witnesses": [{
    "lock": "",
    "inputType": "",
    "outputType": ""
  }, "0x"]
};

sdk签名数据:

"witnesses":["0x5500000010000000550000005500000041000000e2c1d469d5f0c8011c064a9041dd0d556fdb7d95c5a37e0b2778a6e1b115341b17fa8868c2b4ff0cfee9b4196a23cfee72ac240dbe041740dcf15767e334de4901","0x"]}

通过studio签名数据:

"witnesses": ["0x55000000100000005500000055000000410000004c18a8bc16a6403a5e600e9e23c106382f5cdfe8110733dccb7138979cda7dbc14e7fd2350cfa9f7414eb548094fa62bd5de344fd180bae57aeadfcc145eaf4300", "0x"]

共同使用 ckb.rpc.sendTransaction 发送交易,使用sdk签名的数据提示错误 {"code":-3,"message":"Script: ValidationFailure(-31)"},而studio签名数据能发送成功。

GenerateRawTransaction should be generic

Generate Raw Transaction in sdk only accommodates send capacity use case. It should allow for generating different types of transactions. If we want to have a built in transfer capacity method, this method should then use the generate raw transaction.

address module not working

How To Reproduce

  1. setup a new node project
mkdir peter_test&&cd peter_test
npm init
  1. install package
yarn add @nervosnetwork/ckb-sdk-address
  1. save code in index.js
const Address = require('@nervosnetwork/ckb-sdk-address')

const privateKey =
  '7ee543efa447260ecda666296fa64f67c0482e6371e69b3a9cd8ae6ac7646bdf'

const address = new Address(privateKey)
console.log(address)
  1. run
node index.js

Expected

to see the address in console output

Actually Saw

➜  peter-test node index.js 
/Users/peter/Desktop/nervos/ckb-mining/peter-test/index.js:6
const address = new Address(privateKey)
                ^

TypeError: Address is not a constructor

Code hash error when attempting to generate full address from private key.

Error: '0x00' is not a valid code hash
    at toAddressPayload (/home/username/testing/node_modules/@nervosnetwork/ckb-sdk-utils/lib/address/index.js:57:15)
    at bech32Address (/home/username/testing/node_modules/@nervosnetwork/ckb-sdk-utils/lib/address/index.js:69:210)
    at pubkeyToAddress (/home/username/testing/node_modules/@nervosnetwork/ckb-sdk-utils/lib/address/index.js:75:38)
    at privateKeyToAddress (/home/username/testing/node_modules/@nervosnetwork/ckb-sdk-utils/lib/index.js:55:84)
    at Object.<anonymous> (/home/username/testing/index.js:5:57)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)

index.ts:

import {AddressPrefix, AddressType, privateKeyToAddress} from '@nervosnetwork/ckb-sdk-utils';

const PRIVATE_KEY = '0xcd708059624d8301382972808b3e504b5ea3d94e210edf229f48cadcb8fe0989';

const address = privateKeyToAddress(PRIVATE_KEY, {prefix: AddressPrefix.Testnet, type: AddressType.FullVersion});

console.log(address);

How to run contents of test.zip:

npm i
npx tsc
nodejs index.js

test.zip

I can transfer money on the testnet, but I get an error when I switch to the mainnet

Hello, I can use this transfer successfully in the test environment, but when I switch to the main network, an error will be reported. I deleted the private key and need to replace it with yours. The rawTransaction configuration address should also be replaced with your own, please help ,thanks

image

export const bootstrap = async () => {
  const privateKey = "" // example private key

  const ckb = new CKB("https://mainnet.ckb.dev") // instantiate the JS SDK with provided node url

  await ckb.loadDeps() // load the dependencies of secp256k1 algorithm which is used to verify the signature in transaction's witnesses.

  const publicKey = ckb.utils.privateKeyToPublicKey(privateKey)
  /**
   * to see the public key
   */
  // console.log(`Public key: ${publicKey}`)

  const publicKeyHash = `0x${ckb.utils.blake160(publicKey, 'hex')}`
  /**
   * to see the public key hash
   */
  console.log(`Public key hash: ${publicKeyHash}`)

  const addresses = {
    mainnetAddress: ckb.utils.pubkeyToAddress(publicKey, {
      prefix: ckb.utils.AddressPrefix.Mainnet
    }),
    testnetAddress: ckb.utils.pubkeyToAddress(publicKey, {
      prefix: ckb.utils.AddressPrefix.Testnet
    })
  }

  console.log(ckb.config,"ckb.config______")

  /**
   * to see the addresses
   */
  // console.log(JSON.stringify(addresses, null, 2))

  // return


  if (!ckb.config.secp256k1Dep) return
  

  const lock = {
    codeHash: ckb.config.secp256k1Dep.codeHash,
    hashType: ckb.config.secp256k1Dep.hashType,
    args: publicKeyHash
  }



  // console.log(lock,"lock_____")
  /**
   * load cells from lumos as `examples/sendTransactionWithLumosCollector.js` shows
   */
  const unspentCells = await ckb.loadCells({ indexer, CellCollector, lock })

  /**
   * to see the unspent cells
   */
  console.log(unspentCells,"unspentCells____")

  /**
   * send transaction
   */
  const toAddress = ckb.utils.privateKeyToAddress("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", {
    prefix: ckb.utils.AddressPrefix.Testnet
  })

  /**
   * @param fee - transaction fee, can be set in number directly, or use an reconciler to set by SDK
   *                               say, fee: BigInt(100000) means transaction fee is 100000 shannons
   *                                or, fee: { feeRate: '0x7d0', reconciler: ckb.utils.reconcilers.extraInputs } to set transaction fee by reconcilers.extraInputs with feeRate = 2000 shannons/Byte
   *
   * @external https://docs.nervos.org/docs/essays/faq#how-do-you-calculate-transaction-fee
   */
  const rawTransaction = await ckb.generateRawTransaction({
    fromAddress: "ckb1qyq9suqw8dlmfe9zfhpeapceypr3mmjax3mse7sf39",
    toAddress:"ckb1qyqtjfdvsmlksux7zw69zk54krjt46gkf3eqr0zw7x",
    capacity: BigInt(6200000000),
    fee: BigInt(100000),
    safeMode: true,
    cells: unspentCells,
    deps: ckb.config.secp256k1Dep,
  })

  console.log(rawTransaction,"rawTransaction____")


  const signedTx = ckb.signTransaction(privateKey)(rawTransaction)
  /**
   * to see the signed transaction
   */
  console.log(JSON.stringify(signedTx, null, 2))

  const realTxHash = await ckb.rpc.sendTransaction(signedTx)
  /**
   * to see the real transaction hash
   */
  console.log(`The real transaction hash is: ${realTxHash}`)
}

Question about calling `generateRawTransaction` function raise `InsufficientCellCapacity` error

I see the generateRawTransaction function with the safeMode parameter. This parameter controls the use of unspent, but because there is a problem that the remaining spent cannot be less than 61CKB, the problem is that the balance is sufficient, but the transfer fails. Is the code of the link below, Can be changed to if (inputCapacity >= costCapacity + 61) { ?

https://github.com/nervosnetwork/ckb-sdk-js/blob/969a6c5b1807842876f7a90414683d143697ffb0/packages/ckb-sdk-core/src/generateRawTransaction.ts#L86

Unable to get sender via get_transaction rpc

I call RPC get_transaction to get the details of 0x32a6d5be08261efc63ccaa31503fe065cc28ee21b976883f694d062570954e6f and get the result:

{
  "jsonrpc": "2.0",
  "result": {
    "transaction": {
      "cell_deps": [
        {
          "dep_type": "dep_group",
          "out_point": {
            "index": "0x0",
            "tx_hash": "0xe02c8a20a64a336cac1e477b9847888251a30a9bfe2d9050ca7ab59f507b15c7"
          }
        }
      ],
      "hash": "0x32a6d5be08261efc63ccaa31503fe065cc28ee21b976883f694d062570954e6f",
      "header_deps": [],
      "inputs": [
        {
          "previous_output": {
            "index": "0x0",
            "tx_hash": "0x7d8bbb5638926ca86d6f318679c014d31bd3eaea474d1a264e863f1867d2cd69"
          },
          "since": "0x0"
        }
      ],
      "outputs": [
        {
          "capacity": "0x19b45a500",
          "lock": {
            "args": "0xa43856a2fcef41be40170cb473500cc7b30a4dbf",
            "code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
            "hash_type": "type"
          },
          "type": null
        }
      ],
      "outputs_data": [
        "0x"
      ],
      "version": "0x0",
      "witnesses": [
        "0x901f842a476383a52e97dcf68a1f56ef9e5f9f30cd1d871b42aeccb6246a5fee22b9a466bab13c8334698288ec8edee10cfe78851cfd1ae8094794108426e33200"
      ]
    },
    "tx_status": {
      "block_hash": "0x7a7f7296b6922225d4ca35798301139c227b8a8f35033367e89c251317cba91f",
      "status": "committed"
    }
  },
  "id": 1
}

How do I know the sender's address through the results?

npx tsc error

I run npx tsc in docker (FROM node:12.12.0) and gave the following error:

Step 9/11 : RUN npx tsc
 ---> Running in faa6b0c40395
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(2,23): error TS2688: Cannot find type definition file for './types/ckb_rpc'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(13,53): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(14,66): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(15,54): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(16,57): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(18,56): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(19,74): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(27,28): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(28,28): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(29,26): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(30,28): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(31,32): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(32,27): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(33,30): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(34,29): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(35,36): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(36,26): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(37,40): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(38,34): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(39,28): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(40,30): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(41,26): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(42,31): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(43,24): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(44,32): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(46,19): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(52,26): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(53,41): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(59,43): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(60,49): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(67,26): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(68,48): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(69,50): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(70,40): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(71,39): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(72,41): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(73,42): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(74,46): error TS2503: Cannot find namespace 'CKB_RPC'.
node_modules/@nervosnetwork/ckb-sdk-rpc/lib/index.d.ts(75,52): error TS2503: Cannot find namespace 'CKB_RPC'.
The command '/bin/sh -c npx tsc' returned a non-zero code: 2
...

This problem does not appear on my Apple computer.I suspect that it is the case of the folder name in sdk, please see the figure below:
image

Some problems with sdk

1. After I run yarn add @nervosnetwork/ckb-sdk-core, I can't find the folder in the local node_modules:

  • node_modules/@nervosnetwork/ckb-sdk-core/lib/types -> https://github.com/nervosnetwork/ckb-sdk-js/tree/develop/packages/ckb-sdk -core/types

  • node_modules/@nervosnetwork/ckb-sdk-rpc/lib/types/CKB_RPC -> https://github.com/nervosnetwork/ckb-sdk-js/tree/develop/packages/ckb-sdk-rpc/types/CKB_RPC

  • node_modules/@nervosnetwork/ckb-sdk-utils/lib/types/blake2b-wasm -> https://github.com/nervosnetwork/ckb-sdk-js/tree/develop/packages/ckb-sdk-utils/types/blake2b-wasm

Should be missing these folders and files when packaging.

2. My project can be successfully built in the macOS catalina, but fails on docker node:12.12.0.

After my debug, the reason for the guess is that the problem of the folder "node_modules/@nervosnetwork/ckb-sdk-rpc/lib/types/CKB_RPC` is uppercase. After changing to lowercase, my project can be built success.

The second question is consistent with #371 .

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.