pact-lang

Do all modules inherit the Coin contract automatically or is there a required import?


When accepting payment for an NFT I am making, how do I ensure I can call coin.transfer and coin.details from my module?


Solution

  • So the only per-requisites are

    1. Reference to the coin contract
    2. The transfer capability

    You can reference (call) functions on the coin contract by simple calling them like normal functions by doing coin.transfer etc. You can also "import" the whole coin module by doing (use coin) in your contract. This imports all the functions in the coin contract so you can call them like transfer instead of coin.transfer . But this can cause unexpected bugs if not used with caution, so I recommend always calling them like coin.transfer etc

    You need to make sure the "TRANSFER" capability is granted. This can be passed in / specified by the caller when calling the contract. If your contract is the "owner" of the account (i.e. there's a balance for the contract) you can use the install-capability which will let contract grant itself the capability to do transfers for its account