Launch
Send inference request.
Upload Input
Input encrypt: Encrypt inference input by inference node pubkey and requester pubkey.
nodejsimport Elgamal from 'Elgamal'; const elgamal = new Elgamal(); const encrypt = async (inputValue,userPk) => { let node = (await nodeContract.methods.getNode(1).call())[0]; // encrypt const encrypted_by_node = elgamal.encrypt(Buffer.from(inputValue), Buffer.from(node.pubkey, 'hex')); const encrypted_by_user = elgamal.encrypt(Buffer.from(inputValue), Buffer.from(userPk, 'hex')); return (encrypted_by_node,encrypted_by_user) };
Inference Launch: Upload Input info to data node.
nodejsconst (encrypted_by_node,encrypted_by_user) = encrypt(inputValue,userPk); const launch = async (account,node,model,userPk,session) => { const response = await fetch(`{gateService}/inference/launch`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ requester: account, node_id: Number(node.nodeId), model: model, input_encrypt_by_node: encrypted_by_node, input_encrypt_by_user: encrypted_by_user, pubkey: userPk, session: session, }), }); const inputHash = await response.text(); return inputHash; };
Send Request
Send Inference Request: Call Inference contract.
nodejsconst inputHash = launch(account,node,model,userPk,session); const res = await inferenceContract.methods.requestInference(Number(node.nodeId), model, inputHash, userPk, coinAddress, amount).send({ from: account, value: value, // Adjust as needed });