Initialising the Bid
const DatumClient = require('../src/Datum');
let client = new DatumClient();
let ident;
let auctionId = "0x2c26ae8c66d23a2262969a8b176119aea400cc05a82fc625a03321a4dc50a944";
client.createIdentity()
.then(identity => {
ident = identity;
return client.createAuctionBidTransaction(identity.address, auctionId, 100);
})
.then(tx => {
return client.signRawTransaction(tx, new Buffer(ident.privateKey.slice(2), 'hex'));
})
.then(signedTransaction => {
return client.sendSignedTransaction(signedTransaction);
})
.then(result => {
console.log(result);
})
.catch((error) => {
console.log(error);
});
Bidding
const DatumClient = require('../src/Datum');
let client = new DatumClient();
let ident;
let auctionId = '0x2c26ae8c66d23a2262969a8b176119aea400cc05a82fc625a03321a4dc50a944';
client.setPrivateKey('xxxxxxxx');
client.setPublicAddress('xxxxxxx');
client.bidAuction(auctionId, 200)
.then(txResult => {
console.log(result);
})
.catch((error) => {
console.log(error);
});
Settling the Bid
Bid Contract
const DatumClient = require('../src/Datum');
let client = new DatumClient();
let ident;
let auctionId = "0x2c26ae8c66d23a2262969a8b176119aea400cc05a82fc625a03321a4dc50a944";
client.createIdentity()
.then(identity => {
ident = identity;
return client.createAuctionBidTransaction(identity.address, auctionId, 100);
})
.then(tx => {
return client.signRawTransaction(tx, new Buffer(ident.privateKey.slice(2), 'hex'));
})
.then(signedTransaction => {
return client.sendSignedTransaction(signedTransaction);
})
.then(result => {
console.log(result);
})
.catch((error) => {
console.log(error);
});
Acquiring the data stored
const DatumClient = require('../src/Datum');
let client = new DatumClient();
var storageEndPoint = "http://localhost:3000/storage";
var dataId = "0xc8e2ef39a58e4d50c5d1c15fef69cede83fc815cbb99339417ab561c88002e55";
var secret = "Test1jöjöadsfölkjklsdajfökjakösdfkjfölöfsöf23";
client.setPrivateKey('xxxxxxxx');
client.setPublicAddress('xxxxxxx');
client.getSignedTimestampMessage()
.then(message => {
request.post({
headers: { 'content-type': 'application/x-www-form-urlencoded' },
url: storageEndPoint + '/download',
body: "id=" + dataId + "&signature=" + message.signature
}, function (error, response, body) {
return client.decryptPrivate(response.body, secret)
});
})
.then(content => {
console.log(content);
})
.catch((error) => {
console.log(error);
});