-
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
Answer from @ailisp From what works in workspaces-js, binary args need to be provided as Uint8Array (Buffer also works) instead of base64 encoded string:
Modify your code to this should work: const status = await contract.call_js_contract({
args: input
}); reference: Phuong's work on near-cli: https://github.com/near/near-cli/pull/975/files With his impl, I tried this works: near-cli (feat/js-command) bin/near js call js-10.examples.benjiman.testnet getState --accountId <my-testnet-account> --args ''
Scheduling a call in JSVM[jsvm.testnet]: js-10.examples.benjiman.testnet.getState()
Receipt: 5WUa41BUXV1MQufNwrn9d2Kw4GD9Fi9sH5aX4dFBN5Am
Log [jsvm.testnet]: Get state called!
Log [jsvm.testnet]: row1: 1
Log [jsvm.testnet]: row2: 2
Log [jsvm.testnet]: row3: 3
Log [jsvm.testnet]: row4: 4
Log [jsvm.testnet]: row5: 5
Log [jsvm.testnet]: player one: js-10.examples.benjiman.testnet
Log [jsvm.testnet]: player two: benjiman.testnet
Log [jsvm.testnet]: current turn: 1
Log [jsvm.testnet]: game active: true
Transaction Id 8KbY5hQ7SwNAiHmy3WS2Td856Umzxvc4nCbdaAYQG6He
To see the transaction in the transaction explorer, please open this url in your browser
https://explorer.testnet.near.org/transactions/8KbY5hQ7SwNAiHmy3WS2Td856Umzxvc4nCbdaAYQG6He
'' |
Beta Was this translation helpful? Give feedback.
-
@BenKurrek Looking at @ChaoticTempest 's code, I think passing
or
|
Beta Was this translation helpful? Give feedback.
-
Working code: function encodeCall(contract, method, args) {
return Buffer.concat([Buffer.from(contract), Buffer.from([0]), Buffer.from(method), Buffer.from([0]), Buffer.from(args)])
}
let args = encodeCall(contractId, 'getState', '');
const stateView = await wallet.account().viewFunction("jsvm.testnet", 'view_js_contract', args, {
stringify: (val) => val,
}); and function encodeCall(contract, method, args) {
return Buffer.concat([Buffer.from(contract), Buffer.from([0]), Buffer.from(method), Buffer.from([0]), Buffer.from(args)])
}
let args = encodeCall(contractId, 'play', `["${selectedRow}", ${selectedNumber}]`);
const result = await wallet.account().functionCall({
contractId: "jsvm.testnet",
methodName: 'call_js_contract',
args,
gas: "300000000000000"
}); |
Beta Was this translation helpful? Give feedback.
Working code:
and