Configure Custom Giver

Full Sample Codearrow-up-right

By default Account.getDefaultGiver() is Evernode SE giverarrow-up-right. It is integrated into Account module. We will use it. But you can always re-define it with method Account.giver(newGiver: AccountGiver) with the following signature:

/**
 * Object that can be used to send some value to an address 
 */
export type AccountGiver = (address: string, value: number) => Promise<void>;

This guide will help you to implement and configure your custom giver. In the example implementation we will use the same Evernode SE giver with its address, keys and ABI, but you can simply substitute them with your own.

First of all, let's declare our Giver's address, keys and ABI:

// Address of the Giver
const giverAddress = "0:ece57bcc6c530283becbbd8a3b24d3c5987cdddc3c8b7b33be6e4a6312490415";
// Keypair for the Giver
const giverKeys = signerKeys({
    public: "2ada2e65ab8eeab09490e3521415f45b6e42df9c760a639bcf53957550b25a16",
    secret: "172af540e43a524763dd53b26a066d472a97c4de37d5498170564510608250c3",
});

const giverContract = {
    abi: {
        "ABI version": 2,
        header: ["time", "expire"],
        functions: [
            {
                name: "sendTransaction",
                inputs: [
                    {
                        "name": "dest",
                        "type": "address",
                    },
                    {
                        "name": "value",
                        "type": "uint128",
                    },
                    {
                        "name": "bounce",
                        "type": "bool",
                    },
                ],
                outputs: [],
            },
            {
                name: "getMessages",
                inputs: [],
                outputs: [
                    {
                        components: [
                            {
                                name: "hash",
                                type: "uint256",
                            },
                            {
                                name: "expireAt",
                                type: "uint64",
                            },
                        ],
                        name: "messages",
                        type: "tuple[]",
                    },
                ],
            },
            {
                name: "upgrade",
                inputs: [
                    {
                        name: "newcode",
                        type: "cell",
                    },
                ],
                outputs: [],
            },
            {
                name: "constructor",
                inputs: [],
                outputs: [],
            },
        ],
        data: [],
        events: [],
    },
};

Next create Giver's account object, using the values from the previous step:

Now you can implement AccountGiver interface:

In this example, we created separated giverSendTo function in order to be able get result of sendTransaction execution, because AccountGiver.sendTo doesn't return any value.

Configure AppKit to use our Giver:

Thats it. Now any contracts deployment using this client will lead to using your configured Giver.

Usage examples:

Example 1. Contract deployment

In this example we will deploy test HelloWallet contract.

Example 2. Sending some funds from the Giver to a random address

In this example we will send 10 tokens from our Giver to a random address and check messages and transactions, which were created during the operation.

Full Sample Codearrow-up-right

Last updated