This is a translation of the Open Zeppelin Minimal Forwarder contract into ink! complying with ERC2771 standard. It allows you to create your own transaction and signature, but send them to a 3rd party who will submit them to the chain for you through this contract and they pay all the gas fees for you.
The contract is located in contracts/forwarder
. Example contracts Registry/Flipper are also in the contracts/
directory. This is only here for use in testing meta-transaction
.
Forwarder
- Forwarder contracts verify signers' signature and forward transaction requests to actual recipient contracts.MetaTxContext
- Recipient contracts which want to make use of signers' information need to implementsMetaTxContext
trait.Registry
- An example contract implementingMetaTxContext
.Flipper
- An example contract implementingMetaTxContext
.
As a precursor, you will need the Swanky Node or any other development nodes such as Substrate Contracts Node running.
This will compile all contracts under contracts/
folder and generate typescript types and binding codes automatically.
yarn compile
In case it fails for some reason, you can also setup one by one.
- Compile our contracts:
$ cargo contract build --manifest-path ./contracts/forwarder/Cargo.toml
$ cargo contract build --manifest-path ./contracts/flipper/Cargo.toml
$ cargo contract build --manifest-path ./contracts/registry/Cargo.toml
- Install the npm dependencies:
$ yarn
# or
$ npm i
- Copy contract files to the
./tests/artifacts
folder:
$ cp ./target/ink/forwarder/forwarder.contract ./tests/artifacts
$ cp ./target/ink/flipper/flipper.contract ./tests/artifacts
$ cp ./target/ink/registry/registry.contract ./tests/artifacts
And metadata:
$ cp ./target/ink/forwarder/forwarder.contract ./tests/artifacts
$ cp ./target/ink/flipper/flipper.json ./tests/artifacts
$ cp ./target/ink/registry/registry.json ./tests/artifacts
- Generate types and binding files with
typechain-polkadot
:
$ npx typechain-polkadot --in ./tests/artifacts --out ./tests/typedContracts
To run the test suite:
$ yarn test
# or
$ npm run test