Hello,
i am trying to call a function of a contract. Here is the part of the contract:
public stateful function setFoundationLevel(date: int, points: int) =
let oQuery = askOracle(Contract.address, points)
let fl = {date = date, points = points, grade = None, oQuery = Some(oQuery)}
put(state{foundation = Some(fl)})
As you can see, the function refers an oracle, which was deployed before. During
the init function, the oracle address was given to the contract.
public stateful function init(identHash: string, aeName: string, examVerifier: ExamVerifierOracle,
maxPtsPerTraining: int,minPtsForAdvanced: int, minGradeForFoundation: int, oracleFee: int) =
When we run our unit tests, the function is called correctly during the contract object.
await contract.call(‘setFoundationLevel’, { args:
(${trainingDate}, ${examPoints})
, value: oracleFee });
When i call the function during an app:
await client.contractCall(contract_address, 'sophia-address', contract_address, 'setFoundationLevel', { args: `(${date}, ${points})`, value: orcaleFee });
i get an exception :
(node:90922) UnhandledPromiseRejectionWarning: Error: Invocation failed: _b3V0X29mX2dhc0caXYY=
at Object. (/Users//projects/aeternity/isaqb-ui/node_modules/@Albert/aepp-sdk/dist/aepp-sdk.js:1:63728)
at x (/Users//projects/aeternity/isaqb-ui/node_modules/@Albert/aepp-sdk/dist/aepp-sdk.js:1:317336)
at Generator._invoke (/Users//projects/aeternity/isaqb-ui/node_modules/@Albert/aepp-sdk/dist/aepp-sdk.js:1:317124)
at Generator.e.(anonymous function) [as next] (/Users//projects/aeternity/isaqb-ui/node_modules/@Albert/aepp-sdk/dist/aepp-sdk.js:1:317515)
at r (/Users//projects/aeternity/isaqb-ui/node_modules/@Albert/aepp-sdk/dist/aepp-sdk.js:1:1637)
at s (/Users//projects/aeternity/isaqb-ui/node_modules/@Albert/aepp-sdk/dist/aepp-sdk.js:1:1847)
at processTicksAndRejections (internal/process/next_tick.js:81:5)
(node:90922) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:90922) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
When it try to decode the string
_b3V0X29mX2dhc0caXYY=
it doesn’t work. So, i was searching in your source and found the following:
async function call (code, abi, address, name, { args = ‘()’, options = {}, call } = {}) {
const opt = R.merge(this.Ae.defaults, options)const tx = await this.contractCallTx(R.merge(opt, {
callerId: await this.address(),
contractId: address,
callData: await this.contractEncodeCall(code, abi, name, args, call)
}))const { hash, rawTx } = await this.send(tx, opt)
const result = await this.getTxInfo(hash)if (result.returnType === ‘ok’) {
return {
hash,
rawTx,
result,
decode: (type) => this.contractDecodeData(type, result.returnValue)
}
} else {
const error = Buffer.from(result.returnValue.slice(2)).toString()
throw Object.assign(Error(Invocation failed: ${error}
), R.merge(result, { error, decodedError: await this.contractDecodeData(‘string’, result.returnValue) }))
}
}
Please, can anybody explain me, what i am doing wrong?