Sign inSign up

happy365/web3js-test

By happy365

•Updated about 7 years ago

this image is used to test web3.js apis.

Image
1

441

happy365/web3js-test repository overview

⁠1.this image is used to test web3.js apis.
⁠2.there is a private chain in the image,its' information is:
  • chain id is 66
  • has three accounts in this chain, they are: * 0x43c582f2ad90dc6ba9b80a1f74cac4e41e678d8f * 0x00f6d59b1d0d72039686cb05d75b1c6ca4121599 * 0x3c7dcdc9e2d298878e30e255d4c894f9cd3a34e4 and the password is "geth".
  • there is a contract has deployed on the chain,the address of contract is "0x34ec531142ba143be5b88ad4a5a79a6c4eb91f45"
  • the content of the contract is:
pragma solidity >=0.4.22<0.5.0;               
Contract Indentity  {
	# 定义一个结构体来表示一个人的相关信息
	struct Identity {
		string name;
		Sex    sex;
		uint timestamp;
	}
	enum Sex {
		Female,
		Male
	}
	// 定义一个字典,key为文件某个人的ID,value为这个人的相关信息
	mapping(string => Identity) identities;
	// 定义一个事件,用来通知操作的相关信息
	event logAddOnePersonStatus(bool status,uint timestamp,string namer,string id,string message);

	// 定义一个函数,用于用于添加某人用户信息
	function person_set(string name,string id,Sex sex) public {
		// 由于在solidity的字典中,没有办法能够判断一个key是否在字典中已经存在,
		// 所以这里我们通过检查其timestamp是否为0来确认用户信息是否已经存在于区块链上面。
		if (identities[id].timestamp==0) {
			identities[id] = Identity({name: name,timestamp: block.timestamp,sex: sex});
			emit logAddOnePersonStatus(true,block.timestamp,name,id,"add informaiton succeed.");
		}else {
			emit logAddOnePersonStatus(false,block.timestamp,name,id,"person information already exists.");
		}
	}
	// 定义一个获取某人信息的函数get
	function person_get(string pid) public view returns (uint timestamp,string name,string id,Sex sex) {
		return (identities[pid].timestamp,identities[pid].name,pid,identities[pid].sex);
	}
	// print the help information
	function help_information() public pure returns (string){
		return "function: person_set(string name,string id,Sex sex),function: person_get(string id),event: logAddOnePersonStatus";
	}
}
⁠3.if you want to run a container,please use follow command:
     # docker run -d --name web3js-test \
	    -p 8545:8545 \
	   -p 8546:8546 \
	   -p 30303:30303 \
	   happy365/web3js-test:geth-1.9.1 \
	   sh /root/run.sh
⁠4.you can use follow command to attach the geth console:
# docker exec -ti web3js-test sh
# geth attach ipc:/root/.ethereum/geth.ipc

Tag summary

Content type

Image

Digest

Size

20.4 MB

Last updated

about 7 years ago

docker pull happy365/web3js-test:geth-1.9.1