Metamask: Step by step guide after transmission of polygons for intelligent agreement
As a block chain developer of Polygon (formerly Matt), you probably have encountered problems with moving chips from your wallet to an intelligent contract with Metamascus. Don’t worry; In this article, we will guide you through the creation and performance of an action that sends polygons to your contract.
assumptions
Make sure before continuing: Make sure:
- You have a Metamask wallet on your mobile device.
- Your intelligent agreement has been introduced in the polygon chain (polygon.js or remix).
3.
Step 1: Create a new feature
In your agreement, create a new feature that will get polygon -like cods into income and send them to your wallet:
`Solidity
Praga, which is solidity ^0.8.0;
MyContract {
// Set the character and the address of the recipient
UINT256 Public amount;
point to the public recipient;
// to order a function of polygonmatic codes
Log in to order (Uint256, address recipient) Public {
request (quantity> 0, “the amount must be greater than zero”);
Require (recipient! = Address (0), “the recipient must be a valid address”);
// Tokens flows into an agreement
(boool success,) = payble.transferfrom (msg.sender, address (this), quantity);
If (! Success) {
Console.log (“Shipment Failed”);
}
}
}
`
Step 2: Set the action “Log in to login
Add a new feature to the metamask settings with the following features:
* Title
: Log in
* Function name :
* Library : polygon.js
(or remix)
* Args : UINT256 (quantity, address (recipient))
The “quantity” argument should be a sign you sent, and the “recipient” argument is the agreement of your wallet address.
Step 3: Test the Function
- Open with your mobile device.
- Select “Connect”> “Add Metamask” or use an existing account.
At 3 pm. Join Metamask wallet in your Blockchain MUSIGIAL account (polygon.js or remix).
- Go to the contract page and click on the “Credit” feature.
- Write the height of the ID (eg 1 Mumbai) and enter the recipient’s address (contract wallet).
Expected result
Once you have called the “Log in” feature, you should see a message about success in a console that suggests that the cuffs have been transferred to the contract date.
With the procedure of these steps, you have successfully created a new feature that sends polygon -like to the intelligent contract with metamask. Remember to update your contract code accordingly to adjust the new feature.
tips and variations
- If you want to make more thorough errors, consider adding additional inspections or harvesting mechanisms.
- You can also add income to the additional parameters of validation (eg “sum” should be positive with the entire number).
- If you want to use more advanced use cases, you may want to study the use of external libraries such as web3.js or Ethers.js to simplify the brands.