Integration
The ebox On-Chain Escrow revolves around the concept of "boxes", where each box represents a pending transaction. Boxes can be created, cleared or cancelled.
- Creating a box equals depositing funds into the contract as sender, and setting parameters for retrieval: Recipient address, funds to be requested in return (if any), passphrase.
- Clearing a box retrieves the deposited funds, only possible for the legitimate recipient as specified by the sender. The correct passphrase is required, and requested funds (if any) need to be held.
- Cancelling a box is what a user needs to do when there's been a mistake while sending (wrong recipient address, wrong asset, wrong amount of funds).
For each of these operations, increased privacy is available as an optional feature. Requesting funds (OTC trading) is only possible when it is not being used.
Contract addresses for all supported blockchains and the contract ABI are at the bottom of this page.
The following functions execute the main escrow functionality:
Getter functions for retrieving box(es) data:
The
ERC20Interface
type used here is the standard ERC-20 token interface, conforming to the OpenZeppelin IERC20
interface.Creates a box, depositing funds into the contract for later retrieval by the designated recipient, while optionally also requesting funds.
createBox(
address recipient,
ERC20Interface sendToken,
uint sendValue,
ERC20Interface requestToken,
uint requestValue,
bytes32 passHashHash
)
address
recipient
- Address of the recipient legitimated to clear the box
ERC20Interface
sendToken
- Address of the ERC-20 token to be sent
0x0000000000000000000000000000000000000000
for using the chain coin (ETH for Ethereum, BNB for BSC, MATIC for Polygon etc)
uint
sendValue
- Amount of funds to be sent, in Wei
- 1 ETH = 10¹⁸ Wei, same for tokens with 18 decimals
ERC20Interface
requestToken
- Address of the ERC-20 token to be requested
- Irrelevant if just sending, not requesting
- In that case, set
requestValue
to0
(see below)
uint
requestValue
- Amount of funds to be requested, in Wei
- 1 ETH = 10¹⁸ Wei, same for tokens with 18 decimals
- Can be zero (when just sending, not requesting)
bytes32
passHashHash
- Passphrase required from the recipient when clearing the box
- Hashed twice using Keccak / SHA-3 hashing algorithm
- web3.js example:
web3.utils.sha3(web3.utils.sha3(
"passphrase"
))
Clears a box that was previously created by someone else, requiring the correct passphrase and, optionally, holding the funds requested by the sender.
clearBox(
uint boxIndex,
bytes32 passHash
)
uint
boxIndex
bytes32
passHash
- Passphrase set by the sender when creating the box
- Hashed once using Keccak / SHA-3 hashing algorithm
- web3.js example:
web3.utils.sha3(
"passphrase"
)
Cancels one's own box, not requiring the passphrase or holding requested funds (if any).
cancelBox(
uint boxIndex
)
uint
boxIndex
Creates a box with increased privacy, depositing funds into the contract for later retrieval by the designated recipient.
createBoxWithPrivacy(
bytes32 recipientHash,
ERC20Interface sendToken,
uint sendValue,
bytes32 passHashHash
)
bytes32
recipientHash
- Address of the recipient legitimated to clear the box
- Hashed once using Keccak / SHA-3 hashing algorithm
- web3.js example:
web3.utils.sha3(
"address"
)
ERC20Interface
sendToken
- Address of the ERC-20 token to be sent
0x0000000000000000000000000000000000000000
for using the chain coin (ETH for Ethereum, BNB for BSC, MATIC for Polygon etc)
uint
sendValue
- Amount of funds to be sent, in Wei
- 1 ETH = 10¹⁸ Wei, same for tokens with 18 decimals
bytes32
passHashHash
- Passphrase required from the recipient when clearing the box
- Hashed twice using Keccak / SHA-3 hashing algorithm
- web3.js example:
web3.utils.sha3(web3.utils.sha3(
"passphrase"
))
Clears a box with increased privacy that was previously created by someone else, requiring the correct passphrase.
clearBoxWithPrivacy(
uint boxIndex,
bytes32 passHash
)
uint
boxIndex
bytes32
passHash
- Passphrase set by the sender when creating the box
- Hashed once using Keccak / SHA-3 hashing algorithm
- web3.js example:
web3.utils.sha3(
"passphrase"
)
cancelBoxWithPrivacy(
uint boxIndex
)
uint
boxIndex
Returns a list of indexes of all outgoing boxes for the calling address (pending and fulfilled), to be used with getBox.
getBoxesOutgoing()
uint[]
- Array of outgoing box indexes
Returns a list of indexes of all incoming boxes for the calling address (pending and fulfilled), to be used with getBox.
getBoxesIncoming()
uint[]
- Array of incoming box indexes
Returns the transaction data for the specified box.
getBox(
uint boxIndex
)
uint
boxIndex
Returns a list of indexes of all outgoing boxes with increased privacy for the calling address (pending and fulfilled), to be used with getBoxWithPrivacy.
getBoxesOutgoingWithPrivacy()
uint[]
Returns a list of indexes of all incoming boxes with increased privacy for the calling address (pending and fulfilled), to be used with getBoxWithPrivacy.
getBoxesIncomingWithPrivacy()
uint[]
getBoxWithPrivacy(
uint boxIndex
)
uint
boxIndex
These datasets are returned from the respective getter functions, carrying all relevant information about a pending or fulfilled transaction.
The
ERC20Interface
type used here is the standard ERC-20 token interface, conforming to the OpenZeppelin IERC20
interface.struct Box {
address payable sender;
address recipient;
bytes32 passHashHash;
ERC20Interface sendToken;
uint sendValue;
ERC20Interface requestToken;
uint requestValue;
uint timestamp;
bool taken;
}
address
sender
- Address of the sender, able to cancel the box
address
recipient
- Address of the recipient legitimated to clear the box
bytes32
passHashHash
- Passphrase required from the recipient when clearing the box
- Hashed twice using Keccak / SHA-3 hashing algorithm
- web3.js example:
web3.utils.sha3(web3.utils.sha3(
"passphrase"
))
ERC20Interface
sendToken
- Address of the ERC-20 token to be sent
0x0000000000000000000000000000000000000000
for using the chain coin (ETH for Ethereum, BNB for BSC, MATIC for Polygon etc)
uint
sendValue
- Amount of funds to be sent, in Wei
- 1 ETH = 10¹⁸ Wei, same for tokens with 18 decimals
ERC20Interface
requestToken
- Address of the ERC-20 token to be requested
- Irrelevant if just sending, not requesting
- In that case,
requestValue
is0
(see below)
uint
requestValue
- Amount of funds to be requested, in Wei
- 1 ETH = 10¹⁸ Wei, same for tokens with 18 decimals
- Can be zero (when just sending, not requesting)
uint
timestamp
- Unix timestamp at which the box was created, in seconds
bool
taken
- Indicates whether the transaction has been fulfilled (cleared or cancelled)
struct BoxWithPrivacy {
bytes32 senderHash;
bytes32 recipientHash;
bytes32 passHashHash;
ERC20Interface sendToken;
uint sendValue;
uint timestamp;
bool taken;
}
bytes32
senderHash
- Address of the sender, able to cancel the box
- Hashed once using Keccak / SHA-3 hashing algorithm
- web3.js example:
web3.utils.sha3(
"address"
)
bytes32
recipientHash
- Address of the recipient legitimated to clear the box
- Hashed once using Keccak / SHA-3 hashing algorithm
- web3.js example:
web3.utils.sha3(
"address"
)
bytes32
passHashHash
- Passphrase required from the recipient when clearing the box
- Hashed twice using Keccak / SHA-3 hashing algorithm
- web3.js example:
web3.utils.sha3(web3.utils.sha3(
"passphrase"
))
ERC20Interface
sendToken
- Address of the ERC-20 token to be sent
0x0000000000000000000000000000000000000000
for using the chain coin (ETH for Ethereum, BNB for BSC, MATIC for Polygon etc)
uint
sendValue
- Amount of funds to be sent, in Wei
- 1 ETH = 10¹⁸ Wei, same for tokens with 18 decimals
uint
timestamp
- Unix timestamp at which the box was created, in seconds
bool
taken
- Indicates whether the transaction has been fulfilled (cleared or cancelled)
Mainnet
Testnet
Ethereum:
0x501AC1D6103fB2643f2cB93985baAac6f81d1Bc9
BSC:
0x98F8E39032B4dBEC2235B68Bd7CC2505D3793161
Polygon:
0xbD1E729074A14348c78E39b56992f54f0b5d37Ec
Reef Chain:
0x9928e7A8e766E1E5Aa3f7C450bd4D513F8D9B141
Moonriver:
0x33840024177A7DacA3468912363BeD8b425015c5
Moonbeam:
0x33840024177A7DacA3468912363BeD8b425015c5
Rinkeby:
0xAAa491Cf3cA23D59a77eB56Ab487169F4B49e4e2
BSC Testnet:
0xF559344bF9A51bF778fB0Ff38cc690bAF7E61081
Polygon Testnet:
0x6c1cd6434B5Ee4A75605981387cBb3cdDc5596d0
Reef Testnet:
0xE21Dce52e291A788956A4Fd7446F9dc4Eb1f0CF4
[{"inputs":[{"internalType":"uint256","name":"boxIndex","type":"uint256"}],"name":"cancelBox","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"boxIndex","type":"uint256"}],"name":"cancelBoxWithPrivacy","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"boxIndex","type":"uint256"},{"internalType":"bytes32","name":"passHash","type":"bytes32"}],"name":"clearBox","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"boxIndex","type":"uint256"},{"internalType":"bytes32","name":"passHash","type":"bytes32"}],"name":"clearBoxWithPrivacy","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"contract ERC20Interface","name":"sendToken","type":"address"},{"internalType":"uint256","name":"sendValue","type":"uint256"},{"internalType":"contract ERC20Interface","name":"requestToken","type":"address"},{"internalType":"uint256","name":"requestValue","type":"uint256"},{"internalType":"bytes32","name":"passHashHash","type":"bytes32"}],"name":"createBox","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"recipientHash","type":"bytes32"},{"internalType":"contract ERC20Interface","name":"sendToken","type":"address"},{"internalType":"uint256","name":"sendValue","type":"uint256"},{"internalType":"bytes32","name":"passHashHash","type":"bytes32"}],"name":"createBoxWithPrivacy","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"boxIndex","type":"uint256"}],"name":"getBox","outputs":[{"components":[{"internalType":"address payable","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"bytes32","name":"passHashHash","type":"bytes32"},{"internalType":"contract ERC20Interface","name":"sendToken","type":"address"},{"internalType":"uint256","name":"sendValue","type":"uint256"},{"internalType":"contract ERC20Interface","name":"requestToken","type":"address"},{"internalType":"uint256","name":"requestValue","type":"uint256"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"bool","name":"taken","type":"bool"}],"internalType":"struct ethbox.Box","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"boxIndex","type":"uint256"}],"name":"getBoxWithPrivacy","outputs":[{"components":[{"internalType":"bytes32","name":"senderHash","type":"bytes32"},{"internalType":"bytes32","name":"recipientHash","type":"bytes32"},{"internalType":"bytes32","name":"passHashHash","type":"bytes32"},{"internalType":"contract ERC20Interface","name":"sendToken","type":"address"},{"internalType":"uint256","name":"sendValue","type":"uint256"},{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"bool","name":"taken","type":"bool"}],"internalType":"struct ethbox.BoxWithPrivacy","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBoxesIncoming","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBoxesIncomingWithPrivacy","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBoxesOutgoing","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBoxesOutgoingWithPrivacy","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"}]
Last modified 9mo ago