andelf / tronpy

TRON Python Client Library.
MIT License
218 stars 97 forks source link

Proxy Contracts #136

Open spacesudo opened 3 months ago

spacesudo commented 3 months ago

How do I interact with proxy contracts and use functions of write as proxy?

MrNaif2018 commented 2 months ago

Shouldn't it work like any regular contract, like calling methods from ABI on proxied contract?

spacesudo commented 2 months ago

Well unfortunately, it doesn't work. For typescript, there's a trigger smart contract function that is used to call proxy functions but I don't think there's such a thing on tronpy.

MrNaif2018 commented 2 months ago

Could you please point me to such a function in typescript version? If it's indeed required I can implement it

spacesudo commented 2 months ago
const contractAddress = "TTfvyrAz86hbZk5iDpKD78pqLGgi8C7AAw";

export async function buyTRXPump(address, amountTRX) {
  try {
    const transaction = await tronWeb.transactionBuilder.triggerSmartContract(
      contractAddress,
      "purchaseToken(address,uint256)",
      {
        feeLimit: 1000 * 10 ** 6, 
        callValue: amountTRX * 10 ** 6, 
      },
      [
        { type: "address", value: address },
        { type: "uint256", value: "0" },
      ],
      tronWeb.defaultAddress.base58
    );

This is just a code snippet using tronweb

MrNaif2018 commented 2 months ago

I don't see any proxy-specific code here

spacesudo commented 2 months ago

If you look at the contract address, it's a proxy contract and purchaseToken(address,uint256) is a write as proxy function.

My only question here is, as you can see, tronweb has a triggerSmartContract function which can be used in cases like this, but I don't think tronpy has something like this.

If I try to get the contract functions with contract.functions it only lists the normal functions of the contract and not the proxy functions

MrNaif2018 commented 2 months ago

So you get an error like contract has no method named purchaseToken?

spacesudo commented 2 months ago

Exactly

MrNaif2018 commented 2 months ago

Well I find no references of proxy support in their API either plus even found this issue: https://github.com/tronprotocol/tronweb/issues/356

spacesudo commented 2 months ago

Can you take a look at this?

https://github.com/andelf/tronpy/blob/master/tronpy%2Ftron.py#L1072

https://github.com/andelf/tronpy/blob/master/tronpy%2Fcontract.py#L415