AlexanderBuzz / xrpl-php

A PHP library to interact with the XRP Ledger (XRPL) blockchain
ISC License
5 stars 3 forks source link

Make an offer on the DEX #8

Closed nicoeni closed 1 year ago

nicoeni commented 1 year ago

Hi, could we do an offer on the DEX currency - xrp (sell or buy) Thanks you

AlexanderBuzz commented 1 year ago

Hi nicoeni, I will have a look into that. could you describe you use case in more detail?

nicoeni commented 1 year ago

Hello, I want to interact with the DEX. I can do it in JS, but now I want to try it in PHP. To remove an order, I have to do this Request = { "TransactionType": "OfferCancel", "Account": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", "Fee": "12", "Flags": 0, "LastLedgerSequence": 7108629, "OfferSequence": 6, "Sequence": 7 }

And submit it

To put an order, I have to do this Request= { "TransactionType": "OfferCreate", "Account": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", "Fee": "12", "Flags": 0, "LastLedgerSequence": 7108682, "Sequence": 8, "TakerGets": "6000000", "TakerPays": { "currency": "GKO", "issuer": "ruazs5h1qEsqpke88pcqnaseXdm6od2xc", "value": "2" } }

And submit it

Thank you for your help

AlexanderBuzz commented 1 year ago

@nicoeni

You could do this either via a raw request or by using the alloted OfferCreate Request class:

Raw request:

$tx = [
    "TransactionType" => "OfferCreate",
    "Account" => "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX",
    "TakerGets": "6000000",
    "TakerPays" => [
        "currency": "GKO",
        "issuer": "ruazs5h1qEsqpke88pcqnaseXdm6od2xc",
        "value": "2"
    ]
];

$autofilledTx = $client->autofill($tx);

$signedTx = $wallet->sign($autofilledTx);

$body = json_encode([
    "method" => "submit",
    "params" => [
        ["tx_blob" => $signedTx['tx_blob']]
    ]
]);

$response = $client->rawSyncRequest('POST', '', $body);
$content = $response->getBody()->getContents();

print_r(json_decode($content, true));

I'm gonna add the OfferCreate Request to the examples, but you should be able to experiment with the above.

nicoeni commented 1 year ago

Hello and Thank you. Tere are some errors, but it works smoothly. Here is the corrected code:

tx = [ "TransactionType" => "OfferCreate", "Account" => "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", "TakerGets"=> "6000000", "TakerPays" => [ "currency"=> "GKO", "issuer"=> "ruazs5h1qEsqpke88pcqnaseXdm6od2xc", "value"=> "2" ] ];

$autofilledTx = $client->autofill($tx);

$signedTx = $wallet->sign($autofilledTx);

$body = json_encode([ "method" => "submit", "params" => [ ["tx_blob" => $signedTx['tx_blob']] ] ]);

$response = $client->rawSyncRequest('POST', '', $body); $content = $response->getBody()->getContents();

print_r(json_decode($content, true));

AlexanderBuzz commented 1 year ago

Ok, I'm gonna close this then now.