Skip to content

Instantly share code, notes, and snippets.

@raypulver
Created November 20, 2017 19:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raypulver/9820473a4b234ff3e9d0e211eb3b800f to your computer and use it in GitHub Desktop.
Save raypulver/9820473a4b234ff3e9d0e211eb3b800f to your computer and use it in GitHub Desktop.
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