Skip to content

Smart Contract Methods Used For Trading

Please read the Introduction first.

The smart contract methods covered here are the ones needed for deposits and withdrawals to and from the smart contract and querying balances. Also it covers hot to register and remove a delegated signing key.

Contract ABI

Here is a slim version of the ABI which covers these functions. Along with a sample creation of a web3 instance of this contract, which will be used in the examples below.

1
2
3
4
5
6
7
8
9
// web3 1.0 invocation:
// For callback methods please refer to the web3 documentation: https://web3js.readthedocs.io/en/1.0/
const EXCHANGE_CONTRACT_ABI = [ { "constant": false, "inputs": [ { "internalType": "bool", "name": "state", "type": "bool" } ], "name": "setMarketActiveState", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "makerReserve", "type": "address" }, { "internalType": "address payable", "name": "takerReserve", "type": "address" }, { "components": [ { "internalType": "address", "name": "makerToken", "type": "address" }, { "internalType": "address", "name": "takerToken", "type": "address" }, { "internalType": "uint256", "name": "makerAmount", "type": "uint256" }, { "internalType": "uint256", "name": "takerAmount", "type": "uint256" }, { "internalType": "uint256", "name": "makerFee", "type": "uint256" }, { "internalType": "uint256", "name": "takerFee", "type": "uint256" }, { "internalType": "uint256", "name": "gasLimit", "type": "uint256" } ], "internalType": "struct dexBlueStructs.ReserveReserveTrade", "name": "trade", "type": "tuple" }, { "internalType": "bytes32[]", "name": "makerData", "type": "bytes32[]" }, { "internalType": "bytes32[]", "name": "takerData", "type": "bytes32[]" } ], "name": "executeReserveReserveTradeWithData", "outputs": [ { "internalType": "bool", "name": "", "type": "bool" } ], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "components": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput3", "type": "bytes32" } ], "internalType": "struct dexBlueStructs.TradeInputPacked", "name": "tradeInput", "type": "tuple" }, { "internalType": "bytes32[]", "name": "makerData", "type": "bytes32[]" }, { "internalType": "bytes32[]", "name": "takerData", "type": "bytes32[]" } ], "name": "settleReserveReserveTradeWithData", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "components": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput3", "type": "bytes32" } ], "internalType": "struct dexBlueStructs.TradeInputPacked", "name": "tradeInput", "type": "tuple" } ], "name": "settleReserveReserveTrade", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "getReserves", "outputs": [ { "internalType": "address[]", "name": "", "type": "address[]" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "getFeeCollector", "outputs": [ { "internalType": "address", "name": "", "type": "address" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "reserve", "type": "address" } ], "name": "removePublicReserveAddress", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [ { "components": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" } ], "internalType": "struct dexBlueStructs.RingTradeInputPacked", "name": "packed", "type": "tuple" } ], "name": "ringTradeFromInput", "outputs": [ { "components": [ { "internalType": "bool", "name": "isReserve", "type": "bool" }, { "internalType": "uint256", "name": "identifier", "type": "uint256" }, { "internalType": "address", "name": "giveToken", "type": "address" }, { "internalType": "uint256", "name": "giveAmount", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "rebate", "type": "uint256" }, { "internalType": "uint256", "name": "gasLimit", "type": "uint256" } ], "internalType": "struct dexBlueStructs.RingTrade", "name": "", "type": "tuple" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address payable", "name": "collector", "type": "address" } ], "name": "nominateFeeCollector", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "token", "type": "address" }, { "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "depositToken", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "token", "type": "address" }, { "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "directWithdrawal", "outputs": [ { "internalType": "bool", "name": "", "type": "bool" } ], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "token", "type": "address" }, { "internalType": "uint256", "name": "amount", "type": "uint256" }, { "internalType": "uint64", "name": "nonce", "type": "uint64" }, { "internalType": "uint8", "name": "v", "type": "uint8" }, { "internalType": "bytes32", "name": "r", "type": "bytes32" }, { "internalType": "bytes32", "name": "s", "type": "bytes32" }, { "internalType": "address", "name": "receiving_address", "type": "address" } ], "name": "multiSigTransfer", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "delegate", "type": "address" } ], "name": "delegateAddress", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [ { "components": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" }, { "internalType": "bytes32", "name": "r", "type": "bytes32" }, { "internalType": "bytes32", "name": "s", "type": "bytes32" } ], "internalType": "struct dexBlueStructs.OrderInputPacked", "name": "orderInput", "type": "tuple" } ], "name": "orderFromInput", "outputs": [ { "components": [ { "internalType": "address", "name": "sellToken", "type": "address" }, { "internalType": "uint256", "name": "sellAmount", "type": "uint256" }, { "internalType": "address", "name": "buyToken", "type": "address" }, { "internalType": "uint256", "name": "buyAmount", "type": "uint256" }, { "internalType": "uint256", "name": "expiry", "type": "uint256" }, { "internalType": "bytes32", "name": "hash", "type": "bytes32" }, { "internalType": "address", "name": "signee", "type": "address" } ], "internalType": "struct dexBlueStructs.Order", "name": "", "type": "tuple" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "components": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" }, { "internalType": "bytes32", "name": "r", "type": "bytes32" }, { "internalType": "bytes32", "name": "s", "type": "bytes32" } ], "internalType": "struct dexBlueStructs.OrderInputPacked[]", "name": "orderInput", "type": "tuple[]" }, { "components": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput3", "type": "bytes32" } ], "internalType": "struct dexBlueStructs.TradeInputPacked[]", "name": "tradeInput", "type": "tuple[]" } ], "name": "batchSettleTrades", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "token", "type": "address" } ], "name": "removeTokenAddressFromArr", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "token", "type": "address" }, { "internalType": "uint256", "name": "amount", "type": "uint256" }, { "internalType": "uint64", "name": "nonce", "type": "uint64" }, { "internalType": "uint8", "name": "v", "type": "uint8" }, { "internalType": "bytes32", "name": "r", "type": "bytes32" }, { "internalType": "bytes32", "name": "s", "type": "bytes32" }, { "internalType": "address payable", "name": "receiving_address", "type": "address" } ], "name": "multiSigSend", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "makerReserve", "type": "address" }, { "internalType": "address payable", "name": "takerReserve", "type": "address" }, { "components": [ { "internalType": "address", "name": "makerToken", "type": "address" }, { "internalType": "address", "name": "takerToken", "type": "address" }, { "internalType": "uint256", "name": "makerAmount", "type": "uint256" }, { "internalType": "uint256", "name": "takerAmount", "type": "uint256" }, { "internalType": "uint256", "name": "makerFee", "type": "uint256" }, { "internalType": "uint256", "name": "takerFee", "type": "uint256" }, { "internalType": "uint256", "name": "gasLimit", "type": "uint256" } ], "internalType": "struct dexBlueStructs.ReserveReserveTrade", "name": "trade", "type": "tuple" } ], "name": "executeReserveReserveTrade", "outputs": [ { "internalType": "bool", "name": "", "type": "bool" } ], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "sell_token", "type": "address" }, { "internalType": "uint256", "name": "sell_amount", "type": "uint256" }, { "internalType": "address", "name": "buy_token", "type": "address" }, { "internalType": "uint256", "name": "min_output", "type": "uint256" }, { "internalType": "uint256", "name": "deadline", "type": "uint256" } ], "name": "swap", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": true, "stateMutability": "payable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "token", "type": "address" }, { "internalType": "uint256", "name": "index", "type": "uint256" } ], "name": "cacheTokenAddress", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [ { "internalType": "address", "name": "sell_token", "type": "address" }, { "internalType": "uint256", "name": "sell_amount", "type": "uint256" }, { "internalType": "address", "name": "buy_token", "type": "address" } ], "name": "getBestReserve", "outputs": [ { "internalType": "address", "name": "", "type": "address" }, { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [ { "internalType": "address", "name": "token", "type": "address" } ], "name": "getTokenIndex", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "arbiter", "type": "address" }, { "internalType": "bool", "name": "status", "type": "bool" } ], "name": "nominateArbiter", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [ { "components": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput3", "type": "bytes32" } ], "internalType": "struct dexBlueStructs.TradeInputPacked", "name": "packed", "type": "tuple" } ], "name": "reserveTradeFromInput", "outputs": [ { "components": [ { "internalType": "uint256", "name": "orderAmount", "type": "uint256" }, { "internalType": "uint256", "name": "reserveAmount", "type": "uint256" }, { "internalType": "uint256", "name": "orderFee", "type": "uint256" }, { "internalType": "uint256", "name": "reserveFee", "type": "uint256" }, { "internalType": "uint256", "name": "orderRebate", "type": "uint256" }, { "internalType": "uint256", "name": "reserveRebate", "type": "uint256" }, { "internalType": "bool", "name": "orderIsMaker", "type": "bool" }, { "internalType": "uint256", "name": "gasLimit", "type": "uint256" } ], "internalType": "struct dexBlueStructs.ReserveTrade", "name": "", "type": "tuple" } ], "payable": false, "stateMutability": "pure", "type": "function" }, { "constant": false, "inputs": [], "name": "lockFeeCollector", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "sellToken", "type": "address" }, { "internalType": "uint256", "name": "sellAmount", "type": "uint256" }, { "internalType": "address", "name": "buyToken", "type": "address" }, { "internalType": "uint256", "name": "buyAmount", "type": "uint256" }, { "internalType": "address", "name": "reserve", "type": "address" } ], "name": "executeReserveTrade", "outputs": [ { "internalType": "bool", "name": "", "type": "bool" } ], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "sell_token", "type": "address" }, { "internalType": "uint256", "name": "sell_amount", "type": "uint256" }, { "internalType": "address", "name": "buy_token", "type": "address" }, { "internalType": "uint256", "name": "min_output", "type": "uint256" }, { "internalType": "address", "name": "reserve", "type": "address" }, { "internalType": "uint256", "name": "deadline", "type": "uint256" } ], "name": "swapWithReserve", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": true, "stateMutability": "payable", "type": "function" }, { "constant": true, "inputs": [ { "internalType": "address", "name": "user", "type": "address" } ], "name": "getLastBlockedTimestamp", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "bytes32[]", "name": "orderHashes", "type": "bytes32[]" }, { "internalType": "uint8", "name": "v", "type": "uint8" }, { "internalType": "bytes32", "name": "r", "type": "bytes32" }, { "internalType": "bytes32", "name": "s", "type": "bytes32" } ], "name": "multiSigOrderBatchCancel", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "components": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" }, { "internalType": "bytes32", "name": "r", "type": "bytes32" }, { "internalType": "bytes32", "name": "s", "type": "bytes32" } ], "internalType": "struct dexBlueStructs.OrderInputPacked", "name": "orderInput", "type": "tuple" }, { "components": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput3", "type": "bytes32" } ], "internalType": "struct dexBlueStructs.TradeInputPacked", "name": "tradeInput", "type": "tuple" }, { "internalType": "bytes32[]", "name": "data", "type": "bytes32[]" } ], "name": "settleReserveTradeWithData", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [ { "components": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput3", "type": "bytes32" } ], "internalType": "struct dexBlueStructs.TradeInputPacked", "name": "packed", "type": "tuple" } ], "name": "reserveReserveTradeFromInput", "outputs": [ { "components": [ { "internalType": "address", "name": "makerToken", "type": "address" }, { "internalType": "address", "name": "takerToken", "type": "address" }, { "internalType": "uint256", "name": "makerAmount", "type": "uint256" }, { "internalType": "uint256", "name": "takerAmount", "type": "uint256" }, { "internalType": "uint256", "name": "makerFee", "type": "uint256" }, { "internalType": "uint256", "name": "takerFee", "type": "uint256" }, { "internalType": "uint256", "name": "gasLimit", "type": "uint256" } ], "internalType": "struct dexBlueStructs.ReserveReserveTrade", "name": "", "type": "tuple" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "token", "type": "address" }, { "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "blockFundsForSingleSigWithdrawal", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "depositWrappedEther", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [], "name": "depositEther", "outputs": [], "payable": true, "stateMutability": "payable", "type": "function" }, { "constant": true, "inputs": [ { "internalType": "uint256", "name": "index", "type": "uint256" } ], "name": "getTokenFromIndex", "outputs": [ { "internalType": "address", "name": "", "type": "address" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" }, { "internalType": "bytes32", "name": "r", "type": "bytes32" }, { "internalType": "bytes32", "name": "s", "type": "bytes32" } ], "name": "userSigWithdrawal", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "token", "type": "address" }, { "internalType": "uint256", "name": "amount", "type": "uint256" }, { "internalType": "uint64", "name": "nonce", "type": "uint64" }, { "internalType": "uint8", "name": "v", "type": "uint8" }, { "internalType": "bytes32", "name": "r", "type": "bytes32" }, { "internalType": "bytes32", "name": "s", "type": "bytes32" } ], "name": "multiSigWithdrawal", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "token", "type": "address" }, { "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "initiateSingleSigWithdrawal", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "components": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" }, { "internalType": "bytes32", "name": "r", "type": "bytes32" }, { "internalType": "bytes32", "name": "s", "type": "bytes32" } ], "internalType": "struct dexBlueStructs.OrderInputPacked[]", "name": "orderInput", "type": "tuple[]" }, { "components": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" } ], "internalType": "struct dexBlueStructs.RingTradeInputPacked[]", "name": "tradeInput", "type": "tuple[]" } ], "name": "settleRingTrade", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [ { "internalType": "uint256", "name": "index", "type": "uint256" } ], "name": "getReserveFromIndex", "outputs": [ { "internalType": "address", "name": "", "type": "address" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address payable", "name": "new_owner", "type": "address" } ], "name": "changeOwner", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "getTokens", "outputs": [ { "internalType": "address[]", "name": "", "type": "address[]" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "uint256", "name": "waiting_period", "type": "uint256" } ], "name": "changeSingleSigWaitingPeriod", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [ { "components": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput3", "type": "bytes32" } ], "internalType": "struct dexBlueStructs.TradeInputPacked", "name": "packed", "type": "tuple" } ], "name": "tradeFromInput", "outputs": [ { "components": [ { "internalType": "uint256", "name": "makerAmount", "type": "uint256" }, { "internalType": "uint256", "name": "takerAmount", "type": "uint256" }, { "internalType": "uint256", "name": "makerFee", "type": "uint256" }, { "internalType": "uint256", "name": "takerFee", "type": "uint256" }, { "internalType": "uint256", "name": "makerRebate", "type": "uint256" } ], "internalType": "struct dexBlueStructs.Trade", "name": "", "type": "tuple" } ], "payable": false, "stateMutability": "pure", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address payable", "name": "reserve", "type": "address" }, { "internalType": "uint256", "name": "index", "type": "uint256" }, { "internalType": "bool", "name": "is_public", "type": "bool" } ], "name": "cacheReserveAddress", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "components": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" }, { "internalType": "bytes32", "name": "r", "type": "bytes32" }, { "internalType": "bytes32", "name": "s", "type": "bytes32" } ], "internalType": "struct dexBlueStructs.OrderInputPacked", "name": "makerOrderInput", "type": "tuple" }, { "components": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" }, { "internalType": "bytes32", "name": "r", "type": "bytes32" }, { "internalType": "bytes32", "name": "s", "type": "bytes32" } ], "internalType": "struct dexBlueStructs.OrderInputPacked", "name": "takerOrderInput", "type": "tuple" }, { "components": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput3", "type": "bytes32" } ], "internalType": "struct dexBlueStructs.TradeInputPacked", "name": "tradeInput", "type": "tuple" } ], "name": "settleTrade", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [ { "internalType": "address", "name": "sell_token", "type": "address" }, { "internalType": "uint256", "name": "sell_amount", "type": "uint256" }, { "internalType": "address", "name": "buy_token", "type": "address" } ], "name": "getSwapOutput", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "mintGasTokens", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [ { "internalType": "address", "name": "token", "type": "address" }, { "internalType": "address", "name": "holder", "type": "address" } ], "name": "getBalance", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [ { "internalType": "address", "name": "reserve", "type": "address" } ], "name": "getReserveIndex", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "components": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" }, { "internalType": "bytes32", "name": "r", "type": "bytes32" }, { "internalType": "bytes32", "name": "s", "type": "bytes32" } ], "internalType": "struct dexBlueStructs.OrderInputPacked[]", "name": "orderInput", "type": "tuple[]" }, { "components": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" } ], "internalType": "struct dexBlueStructs.RingTradeInputPacked[]", "name": "tradeInput", "type": "tuple[]" }, { "internalType": "bytes32[][]", "name": "data", "type": "bytes32[][]" } ], "name": "settleRingTradeWithData", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "getAvailableGasTokens", "outputs": [ { "internalType": "uint256", "name": "amount", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "delegate", "type": "address" }, { "internalType": "uint8", "name": "v", "type": "uint8" }, { "internalType": "bytes32", "name": "r", "type": "bytes32" }, { "internalType": "bytes32", "name": "s", "type": "bytes32" } ], "name": "revokeDelegation", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [ { "internalType": "address", "name": "token", "type": "address" }, { "internalType": "address", "name": "holder", "type": "address" } ], "name": "getBlocked", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "internalType": "address", "name": "sellToken", "type": "address" }, { "internalType": "uint256", "name": "sellAmount", "type": "uint256" }, { "internalType": "address", "name": "buyToken", "type": "address" }, { "internalType": "uint256", "name": "buyAmount", "type": "uint256" }, { "internalType": "address", "name": "reserve", "type": "address" }, { "internalType": "bytes32[]", "name": "data", "type": "bytes32[]" } ], "name": "executeReserveTradeWithData", "outputs": [ { "internalType": "bool", "name": "", "type": "bool" } ], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "components": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" }, { "internalType": "bytes32", "name": "r", "type": "bytes32" }, { "internalType": "bytes32", "name": "s", "type": "bytes32" } ], "internalType": "struct dexBlueStructs.OrderInputPacked", "name": "orderInput", "type": "tuple" }, { "components": [ { "internalType": "bytes32", "name": "packedInput1", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput2", "type": "bytes32" }, { "internalType": "bytes32", "name": "packedInput3", "type": "bytes32" } ], "internalType": "struct dexBlueStructs.TradeInputPacked", "name": "tradeInput", "type": "tuple" } ], "name": "settleReserveTrade", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "payable": false, "stateMutability": "nonpayable", "type": "constructor" }, { "payable": true, "stateMutability": "payable", "type": "fallback" }, { "anonymous": false, "inputs": [ { "indexed": false, "internalType": "address", "name": "makerAsset", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "makerAmount", "type": "uint256" }, { "indexed": false, "internalType": "address", "name": "takerAsset", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "takerAmount", "type": "uint256" } ], "name": "LogTrade", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "internalType": "address", "name": "soldAsset", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "soldAmount", "type": "uint256" }, { "indexed": false, "internalType": "address", "name": "boughtAsset", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "boughtAmount", "type": "uint256" } ], "name": "LogSwap", "type": "event" }, { "anonymous": false, "inputs": [], "name": "LogTradeFailed", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "internalType": "address", "name": "account", "type": "address" }, { "indexed": false, "internalType": "address", "name": "token", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "LogDeposit", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "internalType": "address", "name": "account", "type": "address" }, { "indexed": false, "internalType": "address", "name": "token", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "LogWithdrawal", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "internalType": "address", "name": "account", "type": "address" }, { "indexed": false, "internalType": "address", "name": "token", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "LogDirectWithdrawal", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "internalType": "address", "name": "account", "type": "address" }, { "indexed": false, "internalType": "address", "name": "token", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "LogBlockedForSingleSigWithdrawal", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "internalType": "address", "name": "account", "type": "address" }, { "indexed": false, "internalType": "address", "name": "token", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } ], "name": "LogSingleSigWithdrawal", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "internalType": "bytes32", "name": "hash", "type": "bytes32" } ], "name": "LogOrderCanceled", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "internalType": "address", "name": "delegator", "type": "address" }, { "indexed": false, "internalType": "address", "name": "delegate", "type": "address" }, { "indexed": false, "internalType": "bool", "name": "status", "type": "bool" } ], "name": "LogDelegateStatus", "type": "event" } ]


const contract = new web3.eth.Contract(
    EXCHANGE_CONTRACT_ABI,
    EXCHANGE_CONTRACT_ADDRESS   // obtained from config.contractAddress or hardcoded "0x000000000000541E251335090AC5B47176AF4f7E"
)

Querying Balances

getBalance

getBalance( address token , address holder ) constant public returns ( uint256 )

Query the deposited balance of an address in the smart contract.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// web3 1.0 invocation:
// For callback methods please refer to the web3 documentation: https://web3js.readthedocs.io/en/1.0/
contract.methods.getBalance(
    TOKEN,      // token whose balance to query (ETH is address(0))
    HOLDER
).call(function(error, balance){
    if(!error){
        balance // in smalest
    }else{
        throw "Cant query balance.";
    }
})

getBlocked

getBlocked( address token , address holder ) constant public returns ( uint256 )

Query the balance addresses blocked via blockFundsForSingleSigWithdrawal.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// web3 1.0 invocation:
// For callback methods please refer to the web3 documentation: https://web3js.readthedocs.io/en/1.0/
contract.methods.getBlocked(
    TOKEN,      // token whose blocked balance to query (ETH is address(0))
    HOLDER
).call(function(error, balance){
    if(!error){
        balance // in smalest
    }else{
        throw "Cant query blocked balance.";
    }
})

Deposit and Withdrawal Events

The events which are emitted from the methods specified.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
event LogDeposit(
        address account,
        address token,
        uint256 amount
    );
event LogWithdrawal(
        address account,
        address token,
        uint256 amount
    );
event LogBlockedForSingleSigWithdrawal(
    address account,
    address token,
    uint256 amount
);
event LogSingleSigWithdrawal(
    address account,
    address token,
    uint256 amount
);

Deposit methods

depositEther

depositEther() public payable

This method can be used to deposit ETH to the smart contract. Please note that there is also a fallback function which will credit Ether sent to the smart contract without data. This means you can do a standard transaction for depositing ETH.

1
2
3
4
5
6
// web3 1.0 invocation:
// For callback methods please refer to the web3 documentation: https://web3js.readthedocs.io/en/1.0/
contract.methods.depositEther().send({
    "from"  : ADDRESS_TO_DEPOSIT_FROM,
    "value" : AMOUNT_TO_DEPOSIT         // in wei
})

depositToken

depositToken( address token , uint256 amount ) public

This method can be used to deposit ERC20 compliant tokens to the smart contract. Please note you first have to set the allowance for the deposit amount in the token contract.

1
2
3
4
5
6
7
8
// web3 1.0 invocation:
// For callback methods please refer to the web3 documentation: https://web3js.readthedocs.io/en/1.0/
contract.methods.depositToken(
    TOKEN_ADDRESS,
    AMOUNT              // amount to deposit
).send({
    "from"  : ADDRESS_TO_DEPOSIT_FROM
})

Expected Smart Contract Events: Deposit

Expected Server Events: ledgerEntryStatus (once the transaction is mined)

Appendix: Set allowance in token contract

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// web3 1.0 invocation:
// for the full ERC20 ABI please refer to the standard, this one only covers the approve method
const ERC20approveABI = [
        {
            "constant"          : false,
            "inputs"            : [{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],
            "name"              : "approve",
            "outputs"           : [{"name":"success","type":"bool"}],
            "payable"           : false,
            "stateMutability"   : "nonpayable",
            "type"              : "function"
        }
    ]
const ERC20Contract = new web3.eth.Contract(
    ERC20approveABI,
    TOKEN_CONTRACT_ADDRESS
)

// For callback methods please refer to the web3 documentation: https://web3js.readthedocs.io/en/1.0/
ERC20Contract.methods.approve(
    EXCHANGE_CONTRACT_ADDRESS,    // obtained from config.contractAddress or hardcoded
    AMOUNT                        // allowance amount
                                  // can be set one-time to maximum:
                                  // "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
).send({
    "from"  : ADDRESS_TO_SET_ALLOWANCE_FROM
})

Multi-Signature Withdrawal Methods

The server signature for the withdrawal can be obtained with signWithdrawal

multiSigWithdrawal

multiSigWithdrawal( address token , uint256 amount , uint64 nonce , uint8 v , bytes32 r , bytes32 s ) public

Initiate an instant withdrawal to your address with servers multi-sig.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// web3 1.0 invocation:
// For callback methods please refer to the web3 documentation: https://web3js.readthedocs.io/en/1.0/
contract.methods.multiSigWithdrawal(
    TOKEN_ADDRESS,      // ETH is address(0)
    AMOUNT,             // amount to withdraw (has to be the one signed by the server)
    NONCE,              // the nonce used in the signature
    V,                  // multi-sig v
    R,                  // multi-sig r
    S                   // multi-sig s
).send({
    "from"  : WITHDRAWAL_ADDRESS    // will receive the token/ETH
})

Expected Smart Contract Events: Withdrawal

Expected Server Events: ledgerEntryStatus (once the transaction is mined)

multiSigSend

multiSigSend( address token , uint256 amount , uint64 nonce , uint8 v , bytes32 r , bytes32 s , address receiving_address) public

Initiate an instant withdrawal to any specified with servers multi-sig. Please make sure the receiving address supports deposits from smart contracts.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// web3 1.0 invocation:
// For callback methods please refer to the web3 documentation: https://web3js.readthedocs.io/en/1.0/
contract.methods.multiSigSend(
    TOKEN_ADDRESS,      // ETH is address(0)
    AMOUNT,             // amount to withdraw (has to be the one signed by the server)
    NONCE,              // the nonce used in the signature
    V,                  // multi-sig v
    R,                  // multi-sig r
    S,                  // multi-sig s
    RECEIVING_ADDRESS   // address to send token/ETH to
).send({
    "from"  : WITHDRAWAL_ADDRESS
})

Expected Smart Contract Events: Withdrawal

Expected Server Events: ledgerEntryStatus (once the transaction is mined)

Single-Signature Withdrawal Method (Fallback)

If for any reason the server should not be reachable for multi sig, you can perform a single-signature withdrawal.

These withdrawals have to be announced 24h in advance before they can be performed. This waiting period ensures trade settlement for all participants in the marketplace. It hinders users to pull funds which are used to back orders on the platform and prevents race conditions between traders and the market platform.

blockFundsForSingleSigWithdrawal

blockFundsForSingleSigWithdrawal( address token , uint256 amount) public

Block funds for single-sig withdrawal. Please note, that when you trade a blocked token its blocked amount will be set to 0.

1
2
3
4
5
6
7
8
9
// web3 1.0 invocation:
// For callback methods please refer to the web3 documentation: https://web3js.readthedocs.io/en/1.0/
contract.methods.blockFundsForSingleSigWithdrawal(
    TOKEN_ADDRESS,      // ETH is address(0)
    AMOUNT,             // amount to block
                        // if this exceeds your available balance on the market platform all your orders will be canceled
).send({
    "from"  : ADDRESS
})

Expected Smart Contract Events: BlockedForSingleSigWithdrawal

Expected Server Events: ledgerEntryStatus (once the transaction is mined)

initiateSingleSigWithdrawal

initiateSingleSigWithdrawal ( address token , uint256 amount) public

Withdraw funds previously blocked by blockFundsForSingleSigWithdrawal after the waiting period.

1
2
3
4
5
6
7
8
// web3 1.0 invocation:
// For callback methods please refer to the web3 documentation: https://web3js.readthedocs.io/en/1.0/
contract.methods.initiateSingleSigWithdrawal(
    TOKEN_ADDRESS,      // ETH is address(0)
    AMOUNT,             // can be smaler or equal to the blocked amount
).send({
    "from"  : ADDRESS
})

Expected Smart Contract Events: SingleSigWithdrawal

Expected Server Events: ledgerEntryStatus (once the transaction is mined)

Delegated Signing Keys (Signature Delegation)

You can also delegate and dedelegate addresses from the webinterface, by clicking in the settings icon and switching to the "delegated signing keys" tab.

For further information about the concept behind delegated signing keys please visit the dedicated API page.

DelegateStatus Event

The event indicated the status of a delegated signing key on the blockchain.

1
2
3
4
5
event DelegateStatus(
        address delegator, // The delegating address
        address delegate,  // The delegates address
        bool status        // indicated wether the delegate is active or not
    );

delegateAddress

delegateAddress( address delegate ) public

Delegate a new address to sign orders on your behalf.

1
2
3
4
5
6
7
// web3 1.0 invocation:
// For callback methods please refer to the web3 documentation: https://web3js.readthedocs.io/en/1.0/
contract.methods.delegateAddress(
    DELEGATE_ADDRESS
).send({
    "from"  : DELEGATING_ADDRESS
})

Expected Smart Contract Events: DelegateStatus

Expected Server Events: delegateStatus (once the transaction is mined)

revokeDelegation

revokeDelegation(address delegate, uint8 v, bytes32 r, bytes32 s) public

Remove signing permissions from a delegated signing key. This key cannot be registered as a delegate again. The arbiters multisig can be obtained with signDelegationRemoval

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
// web3 1.0 invocation:
// For callback methods please refer to the web3 documentation: https://web3js.readthedocs.io/en/1.0/
contract.methods.delegateAddress(
    DELEGATE_ADDRESS,
    V,                  // multi-sig v
    R,                  // multi-sig r
    S,                  // multi-sig s
).send({
    "from"  : DELEGATING_ADDRESS
})

Expected Smart Contract Events: DelegateStatus

Expected Server Events: delegateStatus (once the transaction is mined)