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

TypeError: Expected Buffer #294

Closed
tuhuynh27 opened this issue May 27, 2019 · 1 comment
Closed

TypeError: Expected Buffer #294

tuhuynh27 opened this issue May 27, 2019 · 1 comment

Comments

@tuhuynh27
Copy link

tuhuynh27 commented May 27, 2019

Using "bigchaindb-driver": "4.1.0", and run sample code:

const driver = require("bigchaindb-driver");

// BigchainDB server instance (e.g. https://example.com/api/v1/)
const API_PATH = "http://bigchain.local/api/v1";

// Create a new keypair.
const alice = new driver.Ed25519Keypair();

// Construct a transaction payload
const tx = driver.Transaction.makeCreateTransaction(
  // Define the asset to store, in this example it is the current temperature
  // (in Celsius) for the city of Berlin.
  { city: "Berlin, DE", temperature: 22, datetime: new Date().toString() },

  // Metadata contains information about the transaction itself
  // (can be `null` if not needed)
  { what: "My first BigchainDB transaction" },

  // A transaction needs an output
  [
    driver.Transaction.makeOutput(
      driver.Transaction.makeEd25519Condition(alice.publicKey)
    )
  ],
  alice.publicKey
);

// Sign the transaction with private keys
const txSigned = driver.Transaction.signTransaction(tx, alice.privateKey);

// Send the transaction off to BigchainDB
const conn = new driver.Connection(API_PATH);

conn
  .postTransactionCommit(txSigned)
  .then(retrievedTx =>
    console.log("Transaction", retrievedTx.id, "successfully posted.")
  );

It said:

Desktop/Capstone/bigchain-js is 📦 v1.0.0 via ⬢ v11.14.0 took 9s 
➜ node index.js
/Users/tuhuynh/Desktop/Capstone/bigchain-js/node_modules/base-x/index.js:29
    if (!Buffer.isBuffer(source)) throw new TypeError('Expected Buffer')
                                  ^

TypeError: Expected Buffer
    at Object.encode (/Users/tuhuynh/Desktop/Capstone/bigchain-js/node_modules/base-x/index.js:29:41)
    at new Ed25519Keypair (/Users/tuhuynh/Desktop/Capstone/bigchain-js/node_modules/bigchaindb-driver/dist/node/Ed25519Keypair.js:28:33)
    at Object.<anonymous> (/Users/tuhuynh/Desktop/Capstone/bigchain-js/index.js:7:15)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:877:12)
    at internal/main/run_main_module.js:21:11
@im337
Copy link

im337 commented May 28, 2019

Hey, I had this issue as well.

This fix resolves it - #268 (comment)

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