Create sales
Marketplace listings actions details
1. Request a Nonce
To sign a listing creation request, you would have to use the createNonce mutation with the below parameters :
Your user hex address.
The listing informations in the request input which include the deal kind and the deal id (uuid v4).
Sale Nonce Query example :
Request
mutation CreateSaleNonce($userAddress: Address!) {
saleNonce(
user_address: $userAddress
)
}
Params
{
"userAddress": "0x12776a9dab38cc9a164815053737f8b050ffe42f",
"dealID": "c10e20e5-cd13-4e03-b14a-ef97eb2adaf8"
}
You will then get a string mesage in data.cancelNonce
to sign with sign(keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))
using your predefined web3 client implementation (like signer.signMessage for ethers).
2. Sign the message
According to the EIP712 protocol, the data type of the object (in our case, the listing request) to be signed should be always paired with the signing domain informations.
EIP712 Kalao Domain
The domain informations should be represented as an object with the name
and version
informations like in the javascript example below.
// EIP712 Datas
const domainData = {
name: "Kalao Exchange",
version: "1",
};
The below type should be included in your signed request.
Sale type
const SaleType = {
Sale: [
{ name: "seller", type: "address" },
{ name: "token_address", type: "address" },
{ name: "token_id", type: "uint256" },
{ name: "in_sale_amount", type: "uint256" },
{ name: "unitary_price", type: "uint256" },
{ name: "expiration_ts", type: "uint256" },
{ name: "starting_ts", type: "uint256" },
{ name: "nonce", type: "uint256" },
{ name: "chain_id", type: "uint256" },
{ name: "managed", type: "bool" },
],
};
With these informations, you will have to call the _signTypedData for ethers.js or equivalent for other clients.
Javascript with ethers signer sale listing example :
// EIP712 Signature creation
let signature = await signer._signTypedData(domainData, SaleType, {
seller: nsale.seller,
token_address: nsale.token_address,
token_id: nsale.token_id,
in_sale_amount: nsale.in_sale_amount,
unitary_price: nsale.unitary_price,
expiration_ts: nsale.expiration_ts,
starting_ts: nsale.starting_ts,
nonce: nsale.nonce,
chain_id: nsale.chain_id,
managed: nsale.managed,
});
3. Create the Sale
Send a CreateDeal mutation
You would have to use the createDeal mutation with the below DealRequest input
object parameter :
A
kind
of type DealKind who will be asale
in our case.A
sale
parameter of type OffchainSaleInputThe sale object must carry a
signature
, created previously.
Graphql Example
Request
mutation CreateSale {
createDeal(
input: {
kind: sale
sale: {
asset_id: "0x3caf681231bd99df1d2247f41f8e5f02e750fc5e_1"
token_address: "0x3caf681231bd99df1d2247f41f8e5f02e750fc5e"
token_id: "1"
seller: "0x12776a9dab38cc9a164815053737f8b050ffe42f"
in_sale_amount: "1"
unitary_price: "3000000000000000000"
starting_ts: "1666621648"
expiration_ts: "1955885266"
nonce: 42
chain_id: 43113
min_unitary_price: ""
managed: false
signature: "0x12776a9dab38cc9a164815053737f8b050ffe42f3caf681231bd99df1d2247f4"
}
}
)
}