is a wasy way to wait complete?
yonghumeijj opened this issue · comments
if i want do three step like
1.approve
2.sendTrans
3.transfer
because library is run in task so how can i wait affrove ok then sendtrans then transfer?
Delphi do not have something like await/async
Everything Delphereum does is async. If you want to approve a token and then wait for the transaction to get mined before you transfer (or do anything else), here is how:
const erc20 = TERC20.Create(client, token);
erc20.ApproveEx(owner, spender, web3.Infinite, procedure(rcpt: ITxReceipt; err: IError)
begin
if Assigned(err) then
begin
// handle error
EXIT;
end;
erc20.TransferEx(owner, blah blah blah, procedure(rcpt: ITxReceipt; err: IError)
begin
if Assigned(err) then
begin
// handle error
EXIT;
end;
// continue with your next step
end);
end);
As a general rule, the non-Ex functions -- such as Approve()
and Transfer()
-- return immediately with a hash of the transaction, while the Ex
functions -- such as ApproveEx()
and TransferEx()
-- wait for the transaction to get mined and then return a receipt of the transaction.
Everything Delphereum does is async. If you want to approve a token and then wait for the transaction to get mined before you transfer (or do anything else), here is how:
const erc20 = TERC20.Create(client, token); erc20.ApproveEx(owner, spender, web3.Infinite, procedure(rcpt: ITxReceipt; err: IError) begin if Assigned(err) then begin // handle error EXIT; end; erc20.TransferEx(owner, blah blah blah, procedure(rcpt: ITxReceipt; err: IError) begin if Assigned(err) then begin // handle error EXIT; end; // continue with your next step end); end);
As a general rule, the non-Ex functions -- such as
Approve()
andTransfer()
-- return immediately with a hash of the transaction, while theEx
functions -- such asApproveEx()
andTransferEx()
-- wait for the transaction to get mined and then return a receipt of the transaction.
SendTrans cant do like this. have other way?thanks
Everything Delphereum does is async. If you want to approve a token and then wait for the transaction to get mined before you transfer (or do anything else), here is how:
const erc20 = TERC20.Create(client, token); erc20.ApproveEx(owner, spender, web3.Infinite, procedure(rcpt: ITxReceipt; err: IError) begin if Assigned(err) then begin // handle error EXIT; end; erc20.TransferEx(owner, blah blah blah, procedure(rcpt: ITxReceipt; err: IError) begin if Assigned(err) then begin // handle error EXIT; end; // continue with your next step end); end);
As a general rule, the non-Ex functions -- such as
Approve()
andTransfer()
-- return immediately with a hash of the transaction, while theEx
functions -- such asApproveEx()
andTransferEx()
-- wait for the transaction to get mined and then return a receipt of the transaction.
if i want do many step. this way will be very deep.
xxxxx(x,
procedure
begin
yyyyy(y,
procedure
begin
zzzz(z, procedure
begin
end
)
end
);
end;
)
like this more and more deep....