Copy async function getPermitParamsHash (tezos , contract , entrypoint , parameter) {
const raw_packed = await tezos . rpc .packData ({
data : contract . parameterSchema .Encode (entrypoint , parameter) ,
type : contract . parameterSchema . root .typeWithoutAnnotations () ,
});
return blake .blake2bHex ( hex2buf ( raw_packed .packed) , null , 32 );
}
async function createPermitPayload (tezos , contract , entrypoint , params) {
const signerKey = await tezos . signer .publicKey ();
const permitCounter = await contract .storage () .then (storage => storage . storage .permits_counter);
const paramHash = await getPermitParamsHash (tezos , contract , entrypoint , params);
const chainId = await tezos . rpc .getChainId ();
const bytesToSign = await tezos . rpc .packData ({
data : permitSchema .Encode ({
0 : contract .address ,
1 : chainId ,
2 : permitCounter ,
3 : paramHash ,
}) ,
type : permitSchemaType ,
});
const signature = await tezos . signer .sign ( bytesToSign .packed) .then (s => s .prefixSig);
return [signerKey , signature , paramHash];
}
const dexCoreAddress = "KT1..." ;
const dexCore = await tezos . contract .at (dexCoreAddress);
const transferParams = [
{
from_ : alice .pkh ,
txs : [
{
to_ : bob .pkh ,
token_id : 0 ,
amount : 100 ,
} ,
...
] ,
} ,
...
];
const [ signerKey , signature , permitHash ] = await createPermitPayload (tezos , dexCore , "transfer" , transferParams);
const operation = await dexCore . methods .permit (signerKey , signature , permitHash) .send ();
await operation .confirmation ();