Skip to content

Instantly share code, notes, and snippets.

@kalepail
Last active August 25, 2023 04:11
Show Gist options
  • Save kalepail/c5618b7be4b05f891ffebdae9d144326 to your computer and use it in GitHub Desktop.
Save kalepail/c5618b7be4b05f891ffebdae9d144326 to your computer and use it in GitHub Desktop.
A really easy way to get started with smart contracts on Turing Sign Servers is to upload the code below changing the `hostname` to link to an endpoint where your actual contract logic lives. This allows you to change and modify your contract logic freely. Great for testing before locking in a more immutable contract state.
const { request } = require('https')
module.exports = (body) =>
new Promise((resolve, reject) => {
try {
body = JSON.stringify(body)
const options = {
hostname: 'contract-logic-endpoint.io', // runkit and glitch are my goto services
port: 443,
path: '/',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': body.length,
},
}
const req = request(options, (res) => {
let data = ''
res.on('data', (chunk) => data += chunk)
res.on('end', () => resolve(data))
})
req.on('error', (err) => reject(err))
req.write(body)
req.end()
} catch (err) {reject(err)}
})
.catch((err) => {throw err})
@kalepail
Copy link
Author

kalepail commented Sep 16, 2020

Here's a RunKit example.
https://runkit.com/tyvdh/demo-tss-contract

So to use the above contract logic in this contract gist you'd swap out the hostname value for demo-tss-contract-is1d4km73fep.runkit.sh which is the endpoint for the RunKit notebook. Then you'd simply upload the updated gist to however many TSSs you need and attach their signatures to an account to complete the TSS process! Great for experimenting and testing while you perfect your contract logic.

@kalepail
Copy link
Author

kalepail commented Sep 16, 2020

You can run the contract above using this curl command:

curl -d '{"xdr": "AAAAAgAAAAD9TqMKNYdbjGWHGs/Caz6lvsULdnxCVN1BlrGlMlN2rAAAAGQABxN9AAAAAwAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAD9TqMKNYdbjGWHGs/Caz6lvsULdnxCVN1BlrGlMlN2rAAAAAAAAAAAO5rKAAAAAAAAAAAA"}' -H "X-Turrets: GCQIG3PL446FRQUPURVJ3L3MIAB62YPSNWB7PNU72EUOASYS3FDM6VPY" -X POST https://tss-0.stellar.buzz/contract/8bd5e478c3ec474fb90babee8ae76e34888cddb6178801d8330d04541022e3df

@mistychatmsn
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment