TypeError: Expected Buffer
tuhuynh27 opened this issue · 1 comments
tuhuynh27 commented
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 commented
Hey, I had this issue as well.
This fix resolves it - #268 (comment)