[英]How to encode arguments in AssemblyScript when calling Aurora contract from Near blockchain?
I'm trying to call a contract located in Aurora from a contract located in Near.我正在尝试从位于 Near 的合同中调用位于 Aurora 的合同。 I'm using AssemblyScript and I'm struggling with passing arguments to the Aurora contract itself.
我正在使用 AssemblyScript,并且正在努力将参数传递给 Aurora 合约本身。 I receive
ERR_BORSH_DESERIALIZE
panic from the Aurora contract.我收到来自 Aurora 合约的
ERR_BORSH_DESERIALIZE
恐慌。 Can anybody help me with figuring out how I would encode arguments?谁能帮我弄清楚我将如何编码参数? Here is sample code:
这是示例代码:
import { BorshSerializer } from '@serial-as/borsh'
@serializable
class FunctionCallArgs {
contract: Uint8Array;
input: Uint8Array;
}
export function myFunction(): void {
const args: FunctionCallArgs = {
contract: util.stringToBytes(contractAddress),
input: util.stringToBytes(abiEncodedFn),
};
const argsBorsh = BorshSerializer.encode(args);
ContractPromise.create("aurora", "call", argsBorsh, 100);
}
I managed to find a solution.我设法找到了解决方案。 The flow of calling the contract was right, however I had two errors in implementation.
调用合约的流程是正确的,但是我在执行中有两个错误。
Buffer.from(contractAddress.substring(2), 'hex') // removing 0x prefix is mandatory
const contract = hexToBytes(tokenAddress).reduce((memo, v, i) => {
memo[i] = <u8>v;
return memo;
}, new StaticArray<u8>(20);
And finally monkey-patched "encode_static_array" method in the library to not allocate space before adding bytes to buffer.最后在库中猴子修补的“encode_static_array”方法在将字节添加到缓冲区之前不分配空间。 So removed:
所以删除:
encode_static_array<T>(value: StaticArray<T>): void {
...
this.buffer.store<u32>(value.length); // remove this line
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.