stacks-network / stacks-network/stacks-core

`use-function` built-in to import functions from other contracts

Open
#7,151 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

clarity-new-builtin
Dominant language
Rust
Stars
3.1k
Forks
762
Avg merge
4d 6h
Merged PRs (30d)
76

Description

I suggest the introduction of a new top-level built-in like use-trait.

The use-function built-in is used to import and alias a function of another contract.

contract-a:

(define-data-var some-var uint u0)

(define-public (some-func (some-param uint))
  (ok (var-set some-var some-param))
)

contract-b:

(use-function SP123...contract-a some-func my-some-func)

(define-public (use-some-func)
  (my-some-func u42)
)

The calling context remains the contract the function is defined in. Using my-some-func would be equivalent to substituting it with contract-call?. (It is a call, not a delegate call.)

use-function, like use-trait, can only be used top-level.

The upsides:

  • All contracts for which use-function is used are cached so the external function will be cheaper to call iteratively compared to a series of contract-call?. It is an alternative solution for the issue described in stacks-network/reference#94. Bound by all the same runtime dimensions.
  • Much easier to create library contracts that add functionality.
  • Better composability, don't need to repeat contract-call? nor create a local wrapper function.

Edit: related to stacks-network/stacks-core#7121.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining the existing top-level use-trait behavior and the related stacks-network/stacks-core#7121 issue. Establish how aliasing, contract-call? context, caching, and top-level-only restrictions should work; done means the proposed use-function semantics are agreed and implemented with corresponding validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
blockchain
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.