Trigger Examples

Trigger OnUpgrade

This method will be triggered when a contract / token is upgraded.

Keep in mind that if you don't implement this method it's not possible to upgrade it.

Also add validations to keep it safe and secure.

In this example, this contract will only be updated if it's the owner that called it and reject anything else.

contract test {
    import Runtime;
    global owner: address;

    trigger onUpgrade(from:address)
    {
        Runtime.expect(Runtime.isWitness(owner), "Only the owner can update");
    }
}

Trigger OnMint

This method will be triggered when a token is minted.

In this example, this token will check the symbol, the address that called, and check it was called from within the contract and reject anything else.

Trigger OnBurn

This method will be triggered when a token is burned.

In this example, this contract only burn if it's the owner and reject anything else.

Trigger OnSeries

This method will be triggered when a series is created.

In this example, this contract when a series is created will check if it was the owner that did it and reject anything else.

Trigger OnInfuse

This method will be triggered when a token is infused.

In this example, this token will only accept being infused with the same token and reject anything else.

Trigger OnWrite

This method will be triggered when NFT.Write is called. (When NFT ram is being updated)

In this example, this token will only be able to be updated if it's the owner that called the change and reject anything else.

Trigger OnSend

This method will be triggered when a token is sent.

It's possible to prevent from sending external tokens!

In this example, this account will only accept transfers of KCAL and reject anything else.

Trigger OnReceive

This method will be triggered when a token is received.

It's possible to prevent receiving external tokens!

Example 1

In this example, this account will only accept transfers of KCAL and reject anything else.

Example 2

In this example, any asset sent to this account will be auto-converted into SOUL.

Trigger OnMigrate

this method will be triggered when a user migrates the account.

In this example, this address migrated to another one and we check if it was the actual user that called the method and reject anything else.

Trigger OnKill

In this example, this token will only be killed by the owner and reject anything else.

Last updated