surf
surf copied to clipboard
Support module at different addresses
You can imagine the same module being deployed at different addresses, for example when working with different networks. As it is now though, createEntryPayload uses the address from the ABI to build the function string (e.g. 0x123::my_module::my_function
). It would be nice if createEntryPayload
had support for providing a different address, e.g.:
const data = createEntryPayload(CHESS_ABI, {
moduleAddress: "0x321",
function: "make_move",
typeArguments: [],
functionArguments: [gameAddress as any, source.x, source.y, target.x, target.y, chessJsPieceTypeToNumber(promotion)],
});
@banool good point, will try to support that!
gm @SamuelQZQ I'd like to tackle this one. Idea is to build an ABI constructor.
async function buildABI(ABI=[], address="") : ABI;
If empty ABI, builds from address by fetching module data using RESTful API by using the client Node URL. Substitutes ABI address by provided address.
Built ABI can be used as an argument in .useABI().
Let me know if you have another idea.
@0xPrimata I think add a address params for createEntryPayload
, and directly override the address in createEntryPayload could also work.
This approach is used in Wagmi, see here: https://wagmi.sh/react/api/hooks/useReadContract#type-inference
It has a address
param.
As for the buildABI solution you mentioned, I'm unsure if I understand it correctly. If buildABI fetches the ABI at runtime, the type system won't recognize the functions in the ABI through code parsing.
@SamuelQZQ can this be closed by #113 or not?
Could you clarify here / in the docs how you can provide the module address?
@banool will add in the doc. You can use createViewPayload
or createEntryPayload
like this:
const viewPayload = createViewPayload(COIN_ABI, {
function: 'balance',
functionArguments: ['0x1'],
typeArguments: ['0x1::aptos_coin::AptosCoin'],
address: "override address"
});
Magic!! Love to see it.