Guides/Set up once
Sign in from your server
Use your registered signing key to get a token. Your server sends that token with each payment link request.
Prove which business is calling
- Your server sends its identity ID and public address to Cadmos.
- Cadmos returns a message that expires in two minutes. Check the domain, address, identity and audience, then sign the original message with your private key.
- Your server exchanges the signature for an access token valid for 15 minutes.
Show the sign-in code · Node.js and ethers 6
Save this as sign-in.mjs on your server. It reads the two environment variables from account setup.
import { Wallet } from 'ethers';
const key = new Wallet(process.env.CADMOS_SIGNING_KEY);
const identityId = process.env.CADMOS_IDENTITY_ID.toLowerCase();
const auth = 'https://auth.cadmos.finance/v1/external-auth';
async function post(path, body) {
const response = await fetch(auth + path, {
method: 'POST', redirect: 'error',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
});
if (!response.ok) throw new Error(path + ' returned ' + response.status);
return response.json();
}
const challenge = await post('/challenge', { identityId, address: key.address });
const { challengeId, message, expiresAt } = challenge;
const lines = message.split('\n');
if (lines[0] !== 'auth.cadmos.finance wants you to sign in with your Ethereum account:' ||
lines[1] !== key.address ||
lines[3] !== 'Authenticate external identity ' + identityId + ' for cadmos-pay-be.' ||
lines[5] !== 'URI: ' + auth ||
!lines.includes('Request ID: ' + challengeId) ||
!(Date.parse(expiresAt) > Date.now())) {
throw new Error('Unexpected or expired Cadmos challenge');
}
const signature = await key.signMessage(message);
const { accessToken } = await post('/token', { challengeId, message, signature });
process.stdout.write(accessToken);Use the token for API calls
CADMOS_ACCESS_TOKEN=$(node sign-in.mjs) && export CADMOS_ACCESS_TOKENSend it as Authorization: Bearer <accessToken> only to api.cadmospay.com. Repeat sign-in when it expires.
Create your first payment link.
Next in guidesCreate your first payment link