---
# System prepended metadata

title: Associate tokens

---

# Associate tokens

## Pull relevant tokens (Governance Engagement)

```
with
    $selectedCommunityId as selectedCommunity,
    $tokenAddresses as tokenAddresses
match
    (t:Token)-[:_HAS_MEMBERSHIP_REQUIREMENT]-(e:_Element {_communityId: selectedCommunity})
match
    (w:Wallet)-[:VOTED]->(p:Proposal)-[:HAS_PROPOSAL]-(e:Entity)-[:HAS_STRATEGY]-(t:Token)
where
    t.addresses in tokenAddresses    
with
    t.name as name,
    t.symbol as symbol, 
    t.name + " (" + t.symbol + ") " as nameSymbol, 
    t.address as address,
    "https://etherscan.com/token/" + t.address as etherscanLink,
    count(distinct(w)) as voters
with 
    collect(distinct({
        tokenName: name, 
        tokenSymbol: symbol,
        displayName: nameSymbol, 
        etherscanLink: etherscanLink, 
        voters: voters
    })) as data
return 
{
    token_data: data
}

```

## Add objective

```
with
    tolower($tokenAddress) as address,
    $selectedCommunity as selectedCommunity
match 
    (t:Token {address: address})-[:_HAS_MEMBERSHIP_REQUIREMENT]-(e:_Element)
with 
    e
create
    (obj:_ElementObjective:_GovernanceEngagement:_Unsaved)
set
    e._communityId = selectedCommunity,
    e._chainverseId = apoc.create.uuid(),
    e._displayName = selectedObjective
with
    e, obj
merge
    (e)-[r:_HAS_OBJECTIVE]->(obj)
return
    count(distinct(r)) as objectiveCount
```


## Add token

```
with 
    tolower($tokenAddress) as token,
    $selectedCommmunityId as selectedCommunity
// create element
create
    (e:_Element:_Unsaved {address: token})
set
    e.createdDt = 
set
    e.lastUpdateDt = 
set 
    e._communityId = selectedCommunity 
with 
    e
match
    (c:_Community {_chainverseId: selectedCommunity})
with 
    c, e
merge
    (c)-[r:_HAS_ELEMENT]->(e)
match
    (t:Token {address:token}) 
with
    t,e 
merge
    (e)-[rr:_HAS_MEMBERSHIP_TOKEN]->(t)
return
    count(distinct(rr))
```



## remove unsaved

```
with
    $selectedCommunity as selectedCommunity
match 
    (t:_Unsaved)
where 
    ((t:_Element) or (t:_ElementObjective))
and 
    t._communityId = selectedCommunity
remove
    t:_Unsaved
return
    count(distinct(t)) as saved
```