signum-network / signumjs

SignumJS - Javascript SDK for Signum
https://docs.signum.network/signum/signumjs
Apache License 2.0
17 stars 8 forks source link

`callContractMethod` should accept token also #59

Open ohager opened 1 year ago

ohager commented 1 year ago

Is your feature request related to a problem? Please describe. The current version for callContractMethod allows only SIGNA to be sent. If calls depend on sent tokens, this method cannot be used yet. Allowing token transfers to contract in combination with methods would simplify the usage

Describe the solution you'd like Add optional assetId and quantity for as calling parameters

Describe alternatives you've considered

Current way to do is like this:

        // generate the arguments string
        const methodCall = generateMethodCall({
          methodHash: "99",
          methodArgs: [airdropTokenId],
        });

       // mount as attachment
        const attachment = new AttachmentMessage({
          message: methodCall,
          messageIsText: false,
        });

        // use transferAsset method
        const { unsignedTransactionBytes } = await ledger.asset.transferAsset({
          assetId: contractData.getPledgeTokenId(),
          quantity: quantity.getAtomic(),
          recipientId: this.contractId,
          amountPlanck: contractData.getActivationAmount().getPlanck(),
          feePlanck: fees.cheap.toString(10),
          senderPublicKey: this.getAccount().getPublicKey(),
          attachment,
        });

desired would be:


        const { unsignedTransactionBytes } =
          await ledger.contract.callContractMethod({
            methodHash: "99",
            methodArgs: [],
            contractId: this.contractId,
            assetId: contractData.getPledgeTokenId(),
            assetQuantity: quantity.getAtomic(),
            amountPlanck: contractData.getActivationAmount().getPlanck(),
            feePlanck: fees.cheap.toString(10),
            senderPublicKey: this.getAccount().getPublicKey(),
          });