Comments (6)
from fuels-ts.
If we were to treat Vec<u8>
as number[] | Uint8Array
then we can do simply do this:
import { arrayify } from 'fuels';
const bytecodeFromFile = readFile(pathToBytecode); // string
await contract.functions.verify_bytecode(arrayify(bytecodeFromFile));
On first look, it seems to me that this wouldn't even require any change to the runtime behavior in VecCoder
:
pointer.dynamicData = {
0: concatWithDynamicData(Array.from(value).map((v) => this.coder.encode(v))),
};
Array.from
can accept Uint8Array
out of the box the same way it'd accept a regular number[]
:
Array.from(new Uint8Array([1,2,3]));
// Array(3) [1, 2, 3]
Array.from([1,2,3]);
// Array(3) [1, 2, 3]
from fuels-ts.
@sarahschwartz Could you try my proposal from above? You'd have to do something like this:
await contract.functions.verify_bytecode(arrayify(bytecodeFromFile) as unknown as number[]);
from fuels-ts.
@Dhaiwat10 You mean the contract bytecode needs to be sent as an argument to another contract/function call?
from fuels-ts.
@arboleya precisely
from fuels-ts.
@sarahschwartz Could you try my proposal from above? You'd have to do something like this:
await contract.functions.verify_bytecode(arrayify(bytecodeFromFile) as unknown as number[]);
I tried this, but i get this error:
FuelnautLevel.tsx:136 Error deploying new instance: FuelError: Expected array value.
at VecCoder.encode (index.mjs:723:13)
at eval (index.mjs:687:31)
at Array.map (<anonymous>)
at TupleCoder.encode (index.mjs:686:19)
at FunctionFragment.encodeArguments (index.mjs:1226:27)
at createContractCall (index.mjs:805:21)
Here is my code for reference:
Sway Contract:
fn verify_bytecode_test(bytecode_input: Vec<u8>){
let mut bytecode = bytecode_input;
let root = compute_bytecode_root(bytecode);
log(root);
}
Next.js app:
// server side
const byteCodePath = join(
fuelnautPath,
`${levelKey}/out/debug/${levelKey}.bin`,
);
const bytecode = readFileSync(byteCodePath);
const base64Bytecode = bytecode.toString('base64');
// client side
const bytecodeBuffer = Buffer.from(base64Bytecode, 'base64');
const input = arrayify(bytecodeBuffer) as unknown as number[];
console.log("INPUT:", input)
await contract.functions
.verify_bytecode_test(input)
.txParams({ gasPrice: 1, gasLimit: 1_000_000 })
.call();
I can log the input though:
INPUT: Uint8Array(1260) [116, 0, 0, 3, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 100, 93, 252, 192, 1, 16, 255, 243, 0, 93, 64, 96, 73, 93, 71, 240, 14, 19, 73, 4, 64, 118, 72, 0, 5, 93, 71, 240, 15, 19, 73, 4, 64, 118, 72, 0, 123, 114, 240, 0, 123, 54, 240, 0, 0, 26, 236, 80, 0, 145, 0, 2, 24, 93, 67, 240, 16, 16, 65, 3, 0, 93, 71, 240, 16, 16, 69, 19, 0, 114, 72, 0, 32, 40, 237, 4, 128, 95, 236, 0, 4, 80, 75, 176, 40, …]
from fuels-ts.
Related Issues (20)
- `this.provider.url` is not considering auth url passed
- Provide better ergonomics for proxied contract calls HOT 2
- Remove `signTransaction` method from `FuelConnectorMethods` enum
- Increase tests' timeout to prevent flakiness
- Add Receipts Missing Properties
- Automatic Linear x Github PR integration HOT 3
- Allow FuelConnector `selectNetwork` method to accept optional providerUrl and chainId
- `create-fuels` is not respecting the `fuel-toolchain` file
- Incorrect coder matching from namespaced library
- Implement caching to check latest `fuels` version
- Support Decoding Message Data from `MessageOut` Receipt HOT 1
- Upgrade fuel-core to `0.36.0`
- Update `forc` to `0.63.6`
- Document assets usage
- Logger tests are failing locally
- Deprecate `bech32` address format
- Remove old `docs-snippets` directory
- Fix deprecation on Commander method
- Adjust `types` property in all `package.json` files
- Upgrade `forc` to `0.64.0` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fuels-ts.