Gallery
darkblock-logo
Darkblock Docs
Share
Explore
Developer Integration

Direct Integration

Would you like to use your own viewer? Integrate into a native application? Use Darkblock to store programmatic data like javascript, json, and anything else you can imagine? You can integrate with the protocol more directly and control what happens with the unlockable data.

Listing the available content

To see a list of unlockable content for an NFT you can use this API call:
https://api.darkblock.io/v1/darkblock/info?nft_platform=&nft_id=

Platforms supported:
Ethereum
Solana
Tezos
Polygon
Avalanche
NFT_ID composition for EVM Chains and Tezos: CONTRACT_ID:TOKEN_ID
NFT_ID composition for Solana: TOKEN_ID
https://api.darkblock.io/v1/darkblock/info?nft_id=412EiTpy6Uee5uB1GktpmTJaCUgFgDKLZDKQ419DCAGK&nft_platform=Solana

Example when no Darkblock is found:
https://api.darkblock.io/v1/darkblock/info?nft_id=0x130cfab3817467f532c179d4e6502f5a7e7d44c7:4&nft_platform=Ethereum

Darkblock Protocol Requests

Once Darkblock unlockable content is detected we need to construct a session token to access the content. This token is formed by creating a specific message, the 'msgParams', which includes the current epoch timestamp in milliseconds and the user's wallet address. The wallet signs this message, producing a signature. The session token is thus a combination of this signature, the timestamp, and the chain identifier of the blockchain network in use.

Example js code for creating the signature:

const signInAndGetAccount = async (w3) => {
try {
const address = await w3.eth.getAccounts().then((data) => {
return data[0].toLowerCase()
})
return address
} catch (e) {
alert(`Please make sure you have Metamask installed : ${e.message}`)
}
}


const signMessage = async (message, address, w3) => {
// const message = "Hello World";
const from = address;
const params = [message, from];
const method = "personal_sign";

return await w3.currentProvider.request({
method,
params,
from,
});
};


export const SIGNING_TYPE = {
accessAuth: "access",
upgradeNft: "upgradeNft",
upgradeCollection: "upgradeCollection",
}

const signTypedData = async (data, w3, type) => {
const address = await signInAndGetAccount(w3);
let msgParams = "";

switch (type) {
case SIGNING_TYPE.accessAuth:
msgParams = `You are unlocking content via the Darkblock Protocol.\n\nPlease sign to authenticate.\n\nThis request will not trigger a blockchain transaction or cost any fee.\n\nAuthentication Token: ${data}`;
break;
case SIGNING_TYPE.upgradeNft:
msgParams = `You are interacting with the Darkblock Protocol.\n\nPlease sign to upgrade this NFT.\n\nThis request will not trigger a blockchain transaction or cost any fee.\n\nAuthentication Token: ${data}`;
break;
case SIGNING_TYPE.upgradeCollection:
msgParams = `You are interacting with the Darkblock Protocol.\n\nAttention: You are attempting to upgrade an entire NFT collection!\n\nPlease sign to continue.\n\nThis request will not trigger a blockchain transaction or cost any fee.\nAuthentication Token: ${data}`;
break;
default:
msgParams = `You are unlocking content via the Darkblock Protocol.\n\nPlease sign to authenticate.\n\nThis request will not trigger a blockchain transaction or cost any fee.\n\nAuthentication Token: ${data}`;
break;
}

return new Promise(async (resolve, reject) => {
try {
const signedMessage = await signMessage(msgParams, address, w3);
resolve(signedMessage);
} catch (err) {
reject(err);
}
});
}

export default signTypedData


One session token is needed per chain, and can be cached, as they do not currently expire. They will be prone to expiration in the future, the rules around this will be coming soon based on partner feedback.
Here is the format of the session token: <EPOCH>_<SIGNATURE>_<PLATFORM>

Example:

Signature of 16529845012790x438cba7e454b59a9f897d4731fd3eaef37160c0a
Becomes the following session token:
1652984501279_0x23ddc5b8767a3c2c7c9bab3bdcb86c88a328d21b214e2edad91c6d40b4ad34860c99cfbbf06381c718d8ef3c8068145834ba9a2c8bd442afae7468fef1d10a2f1c_Ethereum

The ArtId can be taken from the Darkblock info response and combined with the session token, owner wallet address, NFT Contract and Token Id, and platform to construct a Gateway request.
https://gateway.darkblock.io/proxy?artid=&session_token=&token_id=&contract=&platform=

Example:
https://gateway.darkblock.io/proxy?artid=9b3aa571-d42f-4699-b09f-6b6c76dab994&session_token=1652985436749_0x1c52329bee2409530b07ddce694df6e75671c3b51bde4aa02f25630f99c369e21d420301b7b7d89eb892b389f1fe32a262c3eae296d2ae81bc05805aca46d8f21c&token_id=30553606573219150352991292921105176340809048341686170040023897669293200900097&contract=0x495f947276749ce646f68ac8c248420045cb7b5e&platform=Ethereum

*(not a working example)

For Ethereum compatible chains you can use this handy-dandy signature tool that allows you to paste in some arbitrary text and create a signature with Metamask:

Questions?

Come hit us up on the !

Share
 
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.