Getting Started

Middleman is in beta as of August 2018 and is not recommended for production use.

Authentication

You'll need an API key to make requests to the Middleman API.

First, create a developer account at https://middleman.cx/signup.

Then go to the Account section (https://middleman.cx/account) and copy your API key.

To authenticate, send your API key in an X-Auth-Key header.

curl -H 'X-Auth-Key: 0000000000000000' https://api.middleman.cx

Woot! Now you are ready to use Middleman.

POST /wallets

The first thing you'll need to do is check if the current user already has a web3 wallet. If they don't, then you will create one for them with Middleman with POST /wallets:

app.js
void async function() {
// check if the user already has a wallet
if (typeof web3 !== 'undefined') {
let web3 = new Web3(web3.currentProvider)
} else {
// create a wallet with Middleman
let wallet = await createWallet('user_id')
web3 = new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io"))
}
}
async function createWallet(userId) {
let wallet = await fetch('https://api.middleman.cx/wallets', {
method: 'POST',
headers: { 'X-Auth-Key': 'MY-AUTH-KEY' },
data: { 'user_id': 'current_user_id_001' }
})
return wallet;
}

GET /wallets

Once a user has a wallet created for them, you can GET their /wallets and use them to interact with the Ethereum blockchain.

Here is how you can use the wallet to sign a transaction and send it to the Ethereum blockchain. You can do anything with a Middleman wallet that you can do with a normal web3 local wallet. To see the full list of options, check out the docs.

app.js
// in the previous example we set wallet = the Middleman wallet object
// and we set the local ethereum node provider to Infura
let transaction = {
"to": "0x8d3e809fbd258083a5ba004a527159da535c8aba",
"value": 0.1,
"gas": 2000000
}
async function signTransaction(address, transaction) {
let signedTransaction = await fetch(`https://api.middleman.cx/wallets/address/${address}/signTransaction`, {
method: 'POST',
headers: { 'X-Auth-Key': 'MY-AUTH-KEY' },
data: { transaction }
})
return signedTransaction;
}
web3.sendSignedTransaction(signTransaction(address, transaction))