Drag and Drop in React

The drag and drop is one the most basic and important actions a person learns when they are first introduced to a computer with a GUI (Graphical User Interface). The first time I remember performing…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Conclusion

integrate signed message recovery directly in your contracts

Meta transactions allow apps to abstract away seed phrases and wallet downloads at first. Users can simply use an app and the notion of gas is abstracted away. Then, after they have earned value, they are much easier to educate about wallets and blockchain.

Native meta transactions let users signal directly to smart contracts with signed messages. For instance, you could transfer an ERC721 (NFTy) that you own to a friend without ever having any ETH to pay for gas.

If you are able to deploy fresh, you should probably be building meta transactions directly in your contracts as opposed to running a proxy contract to forward calls to an existing fleet. For instance, if you create a token, you can provide a native interface in your smart contract for signed messages and relay transactions to allow users to interact without paying for gas.

Once your empty project spins up and you see the Clevis prompt, let’s create our token contract called MetaCoin:

The metaTransfer() function will perform the exact same actions as a normal transfer(), but first it will validate a signature of the hash of the parameters and ecrecover() a signature to prove the signer so everything is still cryptographically backed. Then, instead of doing actions on behalf of msg.sender, it will transfer the signer’s tokens. Finally, we can also wrap in a token reward to incentivise the relayer.

Let’s get our contract compiled and deployed to our local blockchain with:

Let’s uncomment all the scaffolding code in src/App.js and make a few changes. First, let’s simplify the UI down to just showing the address of the MetaCoin contract and following the metaTransfer events:

We will need to fire off our poll() function once the <ContractLoader/> component signals that it is ready:

Next, we’ll create some UI for minting, transferring, and viewing tokens:

We’ll place these components in our main UI:

Don’t forget to run that function in tests/deploy.js:

Now run a full deploy:

And we should see that our MetaMask user can deploy MetaCoins:

We will also need to install axios to make the ajax call work:

Notice that we added a fallback web3 provider and replaced the <MetaMask/> component with the new <Dapparatus/> component. This new component will adapt to the injected web3 and if none exists, it will generate and ephemeral key pair automatically:

We’ll make a few tweaks, but basically we accept a POST and push the arguments and signature on-chian, paying the gas:

Once your relay code is solid, you will need to install the dependencies:

Then you can fire up your relay in the Clevis container with:

Now, try using a MetaMask account with no ETH to transfer tokens. You can even try opening up a browser window in incognito mode or Safari. These accounts should now be able to transfer tokens too!

If you are working on a fresh new set of contracts, take some time to look at adding signed message recovery. The UX benefits are huge when your users are not required to purchase ETH or even have MetaMask downloaded.

UPDATE: I just noticed that I was previously following the “metaTransfer” event but that doesn’t exist in the contract. If you update it to “Transfer” you will see the correct events:

Add a comment

Related posts:

Trump and Biden Reenact the Battle of the Alamo

This is an unconventional Medium story. The idea to send Donald Trump and Joe Biden back in time to the Battle of the Alamo sprung after the recent “Trump Train” versus “Biden Bus” incident in Texas…

Exploring Google Maps in Flutter

Google recently published the official Google Maps plugin for Flutter, adding official support for Google Maps into Flutter. This article will look at how to add Google Maps into a Flutter project…

How To Use A Rewriting API To Refresh Your Blogs

You probably feel a sense of accomplishment when you publish a post and cross it off your SEO to-do list. However, once your content is published, it’s easy to lose sight of it as you work on the…