[Reposted from FVM Forum] How we deployed our custom payment channel smart contracts to an FEVM chain #591
trruckerfling
started this conversation in
Developers
Replies: 1 comment
-
Thanks @trruckerfling . Just want to echo the comment I put on the original thread -- that these instructions are very much out of date now and folks looking to deploy to a FEVM testnet can find more recent instructions on how to do so elsewhere. For example https://www.youtube.com/watch?v=FJK2RDFtSUw . |
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
-
[Reposted from OP @geoknee, Oct 2022]
As of Jan 2022, the FVM Forum will be merging into the Filecoin Community Discussion here, as FVM and Filecoin often go hand-in-hand for builders
TLDR
FEVM is midway through development towards its ultimate goal. Each week, a newly improved iteration with more and more features is deployed to a public FEVM testnet called wallaby. The testnet has a faucet, block explorer and burner wallet. Today, we managed to deploy our on-chain smart contracts (just a singleton contract called NitroAdjudicator) to wallaby, and also invoke a couple of functions! Here’s how we did it:
Context
Hello from team Magmo! We are a research and development team inside of Consensys Mesh, and are developing a new payment channel system for the Filecoin retrieval market, allowing off-chain payments from retrieval clients to retrieval providers.
Since the beginning of this project, it has been uncertain how the on-chain component of our system would be deployed.
In the early days, we considered the option of forking lotus (the main Filecoin blockchain node implementation), replacing or adding to the existing
paych
built-in actor.Then we heard about the Filecoin Virtual Machine, and the possibility of deploying user-defined actors to Filecoin. We got interested in this idea because it mirrored they way we have deployed our system to Ethereum and other Ethereum Virtual Machine networks in the past.
We spent some time tinkering with writing actors in Rust, compiling them to wasm and deploying them to a local “devnet” running an experimental fvm branch of lotus.
Then, we heard about the Filecoin Ethereum Virtual Machine (FEVM), and learnt that some day soon, we could simply reuse both our solidity source code and the Ethereum tooling we were already familiar with to deploy actors to Filecoin!
How we did it
Reusing our existing tooling, we compiled our source code using
hardhat
(which in turn of course calls solc). This gives us an JSON artifact with a bytecode (encoded as a hexadecimal string). We copy-pasted this string into a file callednitro-adjudicator.bin
, and removed the 0x prefix.We then installed Jim Pick’s
wallaby-fevm-msg-signer
CLI tool (v 0.0.9) using npm. We went ahead and generated a seed phrase at https://wallet.glif.io/?network=wallaby 1, saved the phrase and then got some FIL at https://wallaby.network/#faucet using the public key /address corresponding to the generated seed phrase.Creating the actor
Next, we executed this command:
For an explainer about actor addresses, see here https://docs.filecoin.io/about-filecoin/how-filecoin-works/#robust-addresses-versus-id-addresses
Invoking the actor
To invoke the actor, we need the 4 byte sighash to select the adjudicator method we want to call. Since this is abstracted away in a lot of the Ethereum tooling, we went ahead and used https://playground.ethers.org/ to quickly calculate sighashes.
First up, we wanted to try out a method called addressToBytes32, which zero-pads a 20 byte address to 32 bytes. The source code in solidity is:
On the ethers playground, we executed:
With the sighash in hand, we tried invoking this method:
Which produced the following result:
We got an error because our input was malformed. We are used to using ethers.js to connect to contracts, which would have taken the 20 byte (40 hexit) 00000000000000000000000000000000deadbeef and abi encoded it for us, padding it to 32 bytes. Realising this, we did that step manually:
Next up, we wanted to try something more interesting, since this example ended up just returning the input. So we repeated the exercise for the following function which checks a 32 byte word to see if the 12 leading bytes are all zero:
Now back to the ethers playground to get the sighash:
and using Jim Pick’s tool again:
You can see that the result is hex encoded true for 00000000000000000000000000000000000000000000000000000000deadbeef and false for 000a0000000000000000000000000000000000000000000000000000deadbeef .
This is pretty good evidence that we successfully deployed and invoked our smart contract 🎉!
What’s next?
We are going to keep a close eye on the wallaby upgrades and maturing developer tooling. The ultimate goal for us is to run some of our existing payment channel integration tests against an adjudicator deployed to wallaby.
Some minor milestones along the way might be:
We would also love to contribute to the developer tooling (including Jim’s CLI tool) as it evolves.
Other references:
See also this awesome twitch stream from Matt Hamilton, which walks through using the same CLI tool: Twitch.
Beta Was this translation helpful? Give feedback.
All reactions