Skip to content

Instantly share code, notes, and snippets.

@pcaversaccio
Last active April 30, 2023 15:42
Show Gist options
  • Save pcaversaccio/aa9e5d07f949321cbf5cc0b7e4ec6bfd to your computer and use it in GitHub Desktop.
Save pcaversaccio/aa9e5d07f949321cbf5cc0b7e4ec6bfd to your computer and use it in GitHub Desktop.
Example Jupyter Notebook using https://try.vyperlang.org.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "3646ff04",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<boa.vyper.contract.VyperDeployer at 0x7fd5d77d6580>"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%vyper\n",
"\n",
"@external\n",
"@pure\n",
"def foo(x: uint256) -> uint256:\n",
" # Yes Vyper has a built-in integer square root function :)\n",
" return isqrt(x)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "7febbfd9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c = _.deploy() # Deploy the contract\n",
"c.foo(9) # Call `foo` function"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "c4430303",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"501"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c._computation.get_gas_used() # Compute the gas used for calling `foo` with argument 9"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment