Skip to content

Instantly share code, notes, and snippets.

@raypulver

raypulver/order.js

Created Nov 20, 2017
Embed
What would you like to do?
creating an order with IDEX API
const { soliditySha3 } = require('web3-utils');
const {
hashPersonalMessage,
bufferToHex,
toBuffer,
ecsign
} = require('ethereumjs-util')
const { mapValues } = require('lodash');
const contractAddress = '0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208';
const tokenBuy = '0x0000000000000000000000000000000000000000';
const amountBuy = '100000000';
const tokenSell = '0x1111111111111111111111111111111111111111';
const amountSell = '10000';
const address = '0x034767f3c519f361c5ecf46ebfc08981c629d381';
const nonce = 5;
const expires = '10000';
const raw = soliditySha3({
t: 'address',
v: contractAddress
}, {
t: 'address',
v: tokenBuy
}, {
t: 'uint256',
v: amountBuy
}, {
t: 'address',
v: tokenSell
}, {
t: 'uint256',
v: amountSell
}, {
t: 'uint256',
v: expires
}, {
t: 'uint256',
v: nonce
}, {
t: 'address',
v: address
});
const salted = hashPersonalMessage(toBuffer(raw))
const {
v,
r,
s
} = mapValues(ecsign(salted, privateKeyBuffer), (value, key) => key === 'v' ? value : bufferToHex(value));
const request = require('request');
request({
method: 'POST',
url: 'https://api.idex.market/order',
json: {
tokenBuy: tokenBuy,
amountBuy: amountBuy,
tokenSell: tokenSell,
amountSell: amountSell,
address: address,
nonce: 5,
expires: expires,
v: v,
r: r,
s: s
}
}, function (err, resp, body) {
console.log(body);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.