examples: Encoding data when executing an eth_call #144
Unanswered
usebeforefree
asked this question in
Q&A
Replies: 1 comment
-
|
You can use the encoder module for this. You need the abi of that function and then use it for the encoder. You can check the encoder.test.zig file to see how you can achieve this further but here is a simple example const abi = @import("zabi-abi").abitypes;
const func: abi.Function = .{
.type = .function,
.inputs = &.{
.{ .type = .{ .bool = {} }, .name = "foo" },
.{ .type = .{ .string = {} }, .name = "bar" },
},
.name = "Foo",
.stateMutability = .nonpayable,
.outputs = &.{},
};
const fizz: []const u8 = "fizzbuzz";
const encoded = try func.encode(testing.allocator, .{ true, fizz });
defer testing.allocator.free(encoded);
const hex = try std.fmt.allocPrint(testing.allocator, "{s}", .{std.fmt.fmtSliceHexLower(encoded)});
defer testing.allocator.free(hex);
try testing.expectEqualStrings("65c9c0c100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000866697a7a62757a7a000000000000000000000000000000000000000000000000", hex); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I can't seem to find a way to encode the data field of an eth_call.
My goal is to call a function (
exampleFunction(address, uint24)) of a deployed contract.Could you guide me on how to do this, afterwards I will be more than happy to create an example for the given functionality.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions