Need .sethrc for the blockchain you want to connect to. For this demo we'll be using dapp testnet and the setup-testnet.sh script from icetan. This script gets and sets some env variables for us:
ETH_FROMETH_PASSWORDETH_KEYSTOREETH_RPC_URLETH_GAS
dapp testnet (in separate terminal)
In main terminal run: eval "$(setup-testnet.sh 8545)" (where 8545 is the port for the testnet that you just started)
-
Now let's launch the token, from within a repo with the
DSToken.solfile rundapp create DSToken "$(seth --to-bytes32 "$(seth --from-ascii "Sai")")"This will output someseth-sendinfo and then the last line is the address of your new token contract.Breaking this down:
seth --from-ascii "Sai"converts "Sai" from a string to hexdata (returns0x536169)seth --to-bytes32 0x536169converts that hexdata into bytes32 (returns5361690000000000000000000000000000000000000000000000000000000000)- This is then passed to as the first and only arg to the DSToken constructor becoming the symbol for our token.
dapp create DSToken 5361690000000000000000000000000000000000000000000000000000000000deploys the contract and passed our arg.
-
For future use, let's save the address of the contract with
sai=<ADDRESS> -
Let's check the ETH balance of our address with
seth balance $ETH_FROMor withseth ls, both of which should return a huge number in wei.NOTE: If you want, you can convert this number to ETH using
seth --from-wei $(seth balance $ETH_FROM) -
Let's send some ETH with
seth send --value $(seth --to-wei 1.5 eth) <ANY OTHER ADDRESS> -
Confirm that worked with
seth --from-wei $(seth balance $ETH_FROM) -
Ok, now back to our contract: Let's check our Sai symbol is set correctly with
seth --to-ascii $(seth call $sai "symbol()")(returnsSai)Breaking this down:
seth call $sai "symbol()"this makes a call to our $sai contract's getter function for the symbol we set in the constructor. Theseth callcommand receives the<name>(<types>)for our function here and performs the ABI encoding for us. (returns0x5361690000000000000000000000000000000000000000000000000000000000)- We take that return and convert it from the hexdata to ASCII (returns
Sai)
-
Let's check our balance:
seth call $sai "balanceOf(address)" $ETH_FROMshould return0x0000000000000000000000000000000000000000000000000000000000000000since DSToken is not created with any tokens. -
Now we need some tokens minted:
seth send $sai "mint(uint)" $(seth --to-uint256 $(seth --to-wei 1000000 eth))Breaking this down:
seth --to-wei 1000000 ethconverts our 1 million desired tokens into their wei (18 decimal unit) format. (returns1000000000000000000000000)seth --to-uint256 1000000000000000000000000converts our wei token number into uint256 hexdata (returns00000000000000000000000000000000000000000000d3c21bcecceda1000000)- We take that return and send it as the parameter to our transaction that we are
sending to the token'smintfunction. This will mint this many tokens tomsg.sender, in this case our$ETH_FROM.
-
Let's check our balance again:
seth --from-wei $(seth --to-dec $(seth call $sai "balanceOf(address)" $ETH_FROM))should now return1000000.000000000000000000. (thecallfunction returns hexdata (0x00000000000000000000000000000000000000000000d3c21bcecceda1000000that needs to be converted to decimal and then to ether denominations)) -
Let's transfer some Sai, first we'll check the another address balance with
seth call $sai "balanceOf(address)" <OTHER-ADDRESS>and see that it returns 0 (in hex). Now let's do our transfer withseth send $sai "transfer(address,uint)" <OTHER-ADDRESS> $(seth --to-uint256 $(seth --to-wei 1000 eth))