I found a strange behavior of TypeScript SDK during working on a smart contract. It incorrectly passes arguments of type Vec<b256>
to smart contract functions. Here is a simplified example:
Smart contract
The only point of this smart contract is to accept an argument of type Vec<b256>
and log it to see exact values that were accepted by the contract.
contract;
storage {
current_value: u8 = 0,
}
abi MyContract {
#[storage(write)]
fn test_function(value: u8, proof: Vec<b256>) -> u64;
}
impl MyContract for Contract {
#[storage(write)]
fn test_function(value: u8, proof: Vec<b256>) -> u64 {
storage.current_value = value;
let mut i = 0;
while i < proof.len() {
let elem: b256 = proof.get(i).unwrap();
log(elem);
i = i + 1;
}
0
}
}
TypeScript code
async function demonstrateBug() {
const provider = new Provider("https://beta-3.fuel.network/graphql")
// test account
const wallet = Wallet.fromPrivateKey("0x5b2ced0e90112c4b11af7266fc4e768c67e5efc1388830d3867cd4f636721e01", provider)
const contractInstance = ContractAbi__factory.connect(
CONTRACT_ID,
wallet
);
const proof = [
"0x4df54e3446d6beb23c7875c688498ca980bb51faef09c4b89ffb8fff0bbab01d",
"0x8c1ee56d3419ab23abab2a80dc652d659ab5667b889f9e70cb9ed410f031502b",
]
console.log("Expected proof: ", proof)
const result =
await contractInstance.functions.test_function(10, proof)
.txParams({gasPrice: 1, gasLimit: 1000000})
.call();
console.log("Actual proof: ", result.logs)
}
When calling the typescript code, I get the following results:
Expected proof: (2) ['0x4df54e3446d6beb23c7875c688498ca980bb51faef09c4b89ffb8fff0bbab01d', '0x8c1ee56d3419ab23abab2a80dc652d659ab5667b889f9e70cb9ed410f031502b']
Actual proof: (2) ['0x8359cb0aeaa45b3a64ebaf4c2905919a58c2f022197729450000000000000000', '0x000000000000000000000000000000000000000000000000000000001dcd64ff']
It seems like there is a bug in the SDK when passing these arguments.
The same example works correctly with Rust SDK.
fuelup show
active toolchain
-----------------
beta-3-aarch64-apple-darwin (default)
forc : 0.37.3
- forc-client
- forc-deploy : 0.37.3
- forc-run : 0.37.3
- forc-doc : 0.37.3
- forc-explore : 0.28.1
- forc-fmt : 0.37.3
- forc-index : 0.11.2
- forc-lsp : 0.37.3
- forc-tx : 0.37.3
- forc-wallet : 0.2.2
fuel-core : 0.17.11
fuel-indexer : 0.11.2
fuels versions
---------------
forc : 0.39
fuels-ts version: 0.38.0
fuels-rs version: 0.39.0