<aside> ❗

This is a somewhat antiquated page. Please reach out to us.

</aside>

<aside> ℹ️

It is recommended developers familiarize themselves with how the Peanut Protocol works prior to attempting direct contract interactions.

</aside>

The Peanut Smart Contracts are designed for sending non-front-runnable link payments, which can be in the form of various assets. Including ETH, ERC-20 tokens, ERC-721 tokens, ERC-1155 tokens, or combinations thereof!

Contracts use asymmetric ECDSA encryption to verify claim permissions and prevent front running.

Creating a Link

To create a Link there are a few steps required.

  1. Generate the seed and derive asymmetric key pair from ID.
  2. Call the smart contract to deposit funds.
  3. Get index from the event log emitted by deposit call.

Step 1: Generating Keys

Each Peanut Link is protected by a key. The key should be securely created for each Link using secure random data generation features of the platform used.

<aside> ❗

Whilst anything can be used as a key, the following should be avoided:

The SDK uses Ethers to generate the ECDSA key from a seed. Any equivalent function in different languages should also be able to do the same.

function generateKeysFromString(string) {
    var privateKey = ethers.utils.keccak256(
			ethers.utils.toUtf8Bytes(string))
    var wallet = new ethers.Wallet(privateKey)
    return {
        address: wallet.address,
        privateKey: privateKey,
    }
}

It's worth checking that the output from any other crypto library matches the output of the generateKeysFromString function within util.js.

The address and private key from this generation should be stored for later use in the next steps.

Step 2: Calling the Smart Contract

The makeDeposit function allows users to create a Link from a deposit. It handles various token types (ETH, ERC-20, ERC-721, ERC-1155, etc) and stores deposit information in the deposits array.

This function should be called with the correct parameters for the type of crypto being sent along with the last 20 bytes of the public key generated in the previous step.

<aside> ℹ️

Finding the latest address of the contract on the chain in question can be done by looking at the registry file in the github repo. Please note this same smart contract will need to be called in order to claim the funds.

</aside>