New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for calling smart contract endpoints, which expect MultiESDT payment #5
Comments
Hey, thank you. Do you mean
gives you which takes:
so everything that the The most problematic here is the data payload. You can build it like that: import {
TokenPayment,
Transaction,
MultiESDTNFTTransferPayloadBuilder,
Address,
} from '@elrondnetwork/erdjs';
(...)
let paymentOne = TokenPayment.nonFungible("ERDJS-38f249", 1);
let paymentTwo = TokenPayment.fungibleFromAmount("BAR-c80d29", "10.00", 18);
let payments = [paymentOne, paymentTwo];
let payload = new MultiESDTNFTTransferPayloadBuilder()
.setPayments(payments)
.setDestination(new Address("erd1...")) // receiver address
.build();
(...)
// triggerTx from useTransaction hook
triggerTx({
address: erd1..., // address string here, normally receiver address, here it will be the same address as yours (the sender)
gasLimit: 50000 + 1500 * data.length() + 1000000 * payments.length,
data: payload,
value: 0,
});
(...) I haven't tested it. You can read more about how to prepare TokenPayment instances here: https://docs.elrond.com/sdk-and-tools/erdjs/erdjs-cookbook/#preparing-payment-objects. But generally, the useTransaction hook gives a universal tool for probably most types of transactions. The only important thing is the transaction data payload and receiver address. Sometimes, it is the same as the sender because of build-in functions like here. And there is also useScTransaction smart contracts transactions. |
For a custom smart contract, it will probably be similar. You would need to use the
The data payload could differ. I would need to check how standard multi-payment is usually done. |
Thanks for quick reply. The only thing what I wonder right now is how to provide an endpoint name for the SC. Using MultiESDTPayloadBuilder is possible to provide payment and destination, but not the endpoint name. |
do you need to handle something like this?
|
Yea, very similar |
This approach works for me, but probably there is better way to do that
|
Yes, this should also work with built-in I haven't implemented any similar tx call to such custom sc endpoint yet, but I would probably search through erdjs triggerTx({
smartContractAddress: yourScAddressHere,
func: new ContractFunction(yourEndpointNameHere),
gasLimit: requiredGasLimitForYourCustomScEndpoint,
args: [], // here we need to pass the multi value esdt data as argument, probably using `VariadicType` or `CompositeType` from erdjs
value: 0, // value will be 0
}); These are my guessing. I haven't tested it yet. But anyway, the dapp has the tools, the most problematic is how to prepare the data payload or how to prepare the args, like here. Btw. Check here: https://github.com/ElrondNetwork/elrond-sdk-erdjs/blob/main/src/smartcontracts/typesystem/typeMapper.spec.ts. Maybe this will help. And docs on variadic types: https://docs.elrond.com/developers/best-practices/multi-values/#variadic-inputs-and-outputs-multi-values |
Thanks a lot for your hints and clarification! I think this issue can be closed. |
Sure, let us know if you will find a way for args with erdjs. I'll try to play with such cases more. It would be an excellent addition to the scrolls gitbook. I mean the page with real-life examples. So how to call custom smart contracts endpoints with more complicated data structures using erdjs. |
It could be that my thinking about the custom call and custom args is wrong. From what I see here: https://docs.elrond.com/sdk-and-tools/erdpy/smart-contract-interactions/#multi-esdt-transfer looks like the |
Hi @juliancwirko,
First of all thank you for this extra ordinary work. This lightweight template is very impressive.
I would like to ask whether it has also support for calling smart contract endpoints, which expect MultiESDT payment.
Thanks!
The text was updated successfully, but these errors were encountered: