---
# System prepended metadata

title: Interacting with lotus using Expect

---

# Interacting with lotus using Expect

https://linux.die.net/man/1/expect

## 1. IPFS to Filecoin

### 1.1 Pre-requisites

1. Local IPFS node running 
2. Filecoin node running using IFPS
3. File uploaded to IPFS

For more details check [this guide](https://hackmd.io/@vicente/BybIvCpoi#4-Upload-from-IPFS).

### 1.2 Script

```expect=
#!/usr/bin/env expect

# Usage ipfs2filecoin.expect <cid-from-ipfs>

# 1. Pin file locally for availability
spawn ipfs pin add QmfDJ2aYoKEP4cTNMoyXxNbdRbBRC49pxvSbqzUJBT73VU
interact

# 2. Create deal
spawn lotus client deal
set cid [lindex $argv 0]

expect "Data CID" {
    send "$cid\r"
}
expect "Deal duration" {
    send "180\r"
}
expect "Miner Addresses" {
    send "t01129\r"
}
expect "Accept (yes/no):" {
    send "yes\r"
}

interact
```

Example interaction

```
$ ipfs_to_filecoin.expect QmfDJ2aYoKEP4cTNMoyXxNbdRbBRC49pxvSbqzUJBT73VU
```
```
spawn ipfs pin add QmfDJ2aYoKEP4cTNMoyXxNbdRbBRC49pxvSbqzUJBT73VU
pinned QmfDJ2aYoKEP4cTNMoyXxNbdRbBRC49pxvSbqzUJBT73VU recursively
spawn lotus client deal
Data CID (from lotus client import): QmfDJ2aYoKEP4cTNMoyXxNbdRbBRC49pxvSbqzUJBT73VU
.. calculating data size
Deal duration (days): 180
Miner Addresses (f0.. f0..), none to find: t01129
.. querying miner asks
-----
Proposing from t14tg3p2tjxr6wzu6f4p7xzrndk23wdkygfcnnepi
        Balance: 7 FIL

Piece size: 256KiB (Payload size: 220.1KiB)
Duration: 4320h0m0s
Total price: ~0 FIL (0 FIL per epoch)
Verified: false

Accept (yes/no): yes
.. executing
Deal (t01129) CID: bafyreifcyfzl4ebj6vylwjiqipbvfdl2q4fbwnolb3vdlm4yp2w6p6zplq
```