I have an AMM contract running on testnet. The withdraw function in the contract takes in 3 arguments. The contract works fine with goal command but fail when using JS SDK.
My goal command:
goal app call --app-id ${MANAGER_INDEX} --app-arg "str:w" --app-arg "str:1" --app-arg "str:1" --from ${ESCROW_ADDRESS} --app-account ${TEST_ACCOUNT_ADDRESS}
My JS code:
const argParams = splitAndProcessAppArgs(`str:w,str:1,str:1`)
const managerCallTxn = algosdk.makeApplicationCallTxnFromObject({
from: poolAddress,
suggestedParams: params,
appIndex: MANAGER_APP_ID,
appArgs: argParams,
accounts: [request.accountAddress],
onComplete: algosdk.OnApplicationComplete.NoOpOC,
})
function makeUint8Array(arg: any) {
return new Uint8Array(arg)
}
function bytesArray(n: number) {
if (!n) return new ArrayBuffer(0)
const a = []
a.unshift(n & 255)
while (n >= 256) {
n = n >>> 8
a.unshift(n & 255)
}
return new Uint8Array(a)
}
function splitAndProcessAppArgs(inArgs: string) {
const splitArgs: string[] = inArgs.split(',')
const subArgs: Array<string[]> = []
splitArgs.forEach((subArg) => {
subArgs.push(subArg.split(':'))
})
const appArgs: Uint8Array[] = []
subArgs.forEach((subArg) => {
switch (subArg[0]) {
case 'str':
appArgs.push(makeUint8Array(Buffer.from(subArg[1])))
break
case 'int':
appArgs.push(makeUint8Array(bytesArray(parseInt(subArg[1]))))
break
case 'addr':
appArgs.push(algosdk.decodeAddress(subArg[1]).publicKey)
break
case 'b64':
appArgs.push(Buffer.from(subArg[1], 'base64'))
break
default:
throw Error(`did not recognize app arg of type${subArg[0]}`)
}
})
console.log('app args:', appArgs)
return appArgs
}
Error:
{"message":"transaction {_struct:{} Sig:[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] Msig:{_struct:{} Version:0 Threshold:0 Subsigs:[]} Lsig:{_struct:{} Logic:[6 32 9 1 6 189 174 254 4 0 173 214 164 42 219 241 244 5 219 214 164 42 3 4 51 1 25 34 18 51 1 27 33 7 18 16 55 1 26 0 128 1 98 18 16 64 2 231 55 1 26 0 128 2 115 49 18 64 2 108 55 1 26 0 128 2 115 50 18 64 1 241 55 1 26 0 128 1 97 18 64 1 119 55 1 26 0 128 1 119 18 64 0 249 55 1 26 0 128 1 114 18 64 0 127 55 1 26 0 128 1 112 18 64 0 1 0 51 1 25 37 18 55 1 28 1 49 0 19 16 51 1 16 35 18 16 51 1 24 33 6 18 16 51 2 16 35 18 16 51 2 24 33 4 18 16 68 34 51 1 1 51 2 1 8 51 3 1 8 51 4 1 8 53 0 34 16 51 0 16 34 18 51 0 0 49 0 19 16 51 0 7 49 0 18 16 49 9 50 3 18 16 49 21 50 3 18 16 49 32 50 3 18 16 33 5 36 13 16 51 0 8 52 0 15 16 68 34 16 66 2 180 51 1 25 37 18 55 1 28 1 49 0 19 16 51 1 16 35 18 16 51 1 24 33 6 18 16 51 2 16 35 18 16 51 2 24 33 4 18 16 68 34 51 1 1 51 2 1 8 51 3 1 8 53 0 34 16 51 0 16 34 18 51 0 0 49 0 19 16 51 0 7 49 0 18 16 49 9 50 3 18 16 49 21 50 3 18 16 49 32 50 3 18 16 33 5 36 13 16 51 0 8 52 0 15 16 68 34 16 66 2 69 51 1 25 37 18 55 1 28 1 49 0 19 16 51 1 16 35 18 16 51 1 24 33 6 18 16 51 2 16 35 18 16 51 2 24 33 4 18 16 68 34 51 1 1 51 2 1 8 51 4 1 8 51 5 1 8 53 0 34 16 51 0 16 34 18 51 0 0 49 0 19 16 51 0 7 49 0 18 16 49 9 50 3 18 16 49 21 50 3 18 16 49 32 50 3 18 16 33 5 36 13 16 51 0 8 52 0 15 16 68 34 16 66 1 210 51 1 25 37 18 55 1 28 1 49 0 19 16 51 1 16 35 18 16 51 1 24 33 6 18 16 51 2 16 35 18 16 51 2 24 33 4 18 16 68 34 51 1 1 51 2 1 8 51 5 1 8 53 0 34 16 51 0 16 34 18 51 0 0 49 0 19 16 51 0 7 49 0 18 16 49 9 50 3 18 16 49 21 50 3 18 16 49 32 50 3 18 16 33 5 36 13 16 51 0 8 52 0 15 16 68 34 16 66 1 99 51 1 25 37 18 55 1 28 1 49 0 19 16 51 1 16 35 18 16 51 1 24 33 6 18 16 51 2 16 35 18 16 51 2 24 33 4 18 16 68 34 51 1 1 51 2 1 8 51 4 1 8 53 0 34 16 51 0 16 34 18 51 0 0 49 0 19 16 51 0 7 49 0 18 16 49 9 50 3 18 16 49 21 50 3 18 16 49 32 50 3 18 16 33 5 36 13 16 51 0 8 52 0 15 16 68 34 16 66 0 244 51 1 25 37 18 55 1 28 1 49 0 19 16 51 1 16 35 18 16 51 1 24 33 6 18 16 51 2 16 35 18 16 51 2 24 33 4 18 16 68 34 51 1 1 51 2 1 8 51 4 1 8 53 0 34 16 51 0 16 34 18 51 0 0 49 0 19 16 51 0 7 49 0 18 16 49 9 50 3 18 16 49 21 50 3 18 16 49 32 50 3 18 16 33 5 36 13 16 51 0 8 52 0 15 16 68 34 16 66 0 133 51 1 16 35 18 51 1 25 34 18 16 51 1 24 33 4 18 16 51 2 16 33 7 18 16 51 3 16 33 8 18 16 51 1 1 51 2 1 8 51 3 1 8 53 0 36 37 18 64 0 73 50 4 129 5 18 52 0 51 4 1 8 53 0 34 16 68 34 16 51 0 16 34 18 51 0 0 49 0 19 16 51 0 7 49 0 18 16 49 9 50 3 18 16 49 21 50 3 18 16 49 32 50 3 18 16 33 5 36 13 16 51 0 8 52 0 15 16 68 34 16 66 0 9 50 4 33 8 18 68 66 255 190 67] Sig:[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] Msig:{_struct:{} Version:0 Threshold:0 Subsigs:[]} Args:[]} Txn:{_struct:{} Type:appl Header:{_struct:{} Sender:CGXRO6ILEXL7T4L2DFLAYNWL6KMAN6YATOJQ2UKAUEMRHLKARPAVFTZWIU Fee:{Raw:1000} FirstValid:21762602 LastValid:21763602 Note:[] GenesisID:testnet-v1.0 GenesisHash:JBR3KGFEWPEE5SAQ6IWU6EEBZMHXD4CZU6WCBXWGF57XBZIJHIRA Group:U53OEJOMREZS47RMRV2YVTKRQONPB25WZESDNJSYR2MWNJ23OL2A Lease:[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] RekeyTo:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ} KeyregTxnFields:{_struct:{} VotePK:[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] SelectionPK:[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] StateProofPK:[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] VoteFirst:0 VoteLast:0 VoteKeyDilution:0 Nonparticipation:false} PaymentTxnFields:{_struct:{} Receiver:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ Amount:{Raw:0} CloseRemainderTo:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ} AssetConfigTxnFields:{_struct:{} ConfigAsset:0 AssetParams:{_struct:{} Total:0 Decimals:0 DefaultFrozen:false UnitName: AssetName: URL: MetadataHash:[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] Manager:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ Reserve:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ Freeze:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ Clawback:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ}} AssetTransferTxnFields:{_struct:{} XferAsset:0 AssetAmount:0 AssetSender:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ AssetReceiver:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ AssetCloseTo:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ} AssetFreezeTxnFields:{_struct:{} FreezeAccount:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ FreezeAsset:0 AssetFrozen:false} ApplicationCallTxnFields:{_struct:{} ApplicationID:88681307 OnCompletion:NoOpOC ApplicationArgs:[[119] [49] [49]] Accounts:[4XXEXPU2M7LK5IOE5QQUA6JRLPNZ76GDOZ6QII5MDJEQ46HZ4YLVEO3QI4] ForeignApps:[88681261] ForeignAssets:[] LocalStateSchema:{_struct:{} NumUint:0 NumByteSlice:0} GlobalStateSchema:{_struct:{} NumUint:0 NumByteSlice:0} ApprovalProgram:[] ClearStateProgram:[] ExtraProgramPages:0} CompactCertTxnFields:{_struct:{} CertRound:0 CertType:0 Cert:{_struct:{} SigCommit:[] SignedWeight:0 SigProofs:{_struct:{} Path:[] HashFactory:{_struct:{} HashType:sha512_256} TreeDepth:0} PartProofs:{_struct:{} Path:[] HashFactory:{_struct:{} HashType:sha512_256} TreeDepth:0} Reveals:map[]}}} AuthAddr:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ} invalid : transaction 7TTUTT5RMI5HH6VYLTTE5B3A7MJ2Q263JR2RFBBL6FYOMZ5J747A: rejected by logic err=invalid ApplicationArgs index 0"}